/usr/lib/sitesummary/nagios-plugins/check_cups_queue is in sitesummary-client 0.1.9.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #!/bin/bash
# CUPS print queue plugin for Nagios
# Written by John E. Vincent (nagios-plugs@lusis.org)
# Last Modified: 06-27-2006
# License: GNU General Public License, according to
# <c841561b1002182124g7ca4e8fbme6574b3a558acc80@mail.gmail.com>
# on debian-edu@lists.debian.org
#
# Description:
#
# This plugin will check the status of a remote CUPS
# print queue. It will provide the size of the queue
# and optionally the age of the queue
#
# Location of the lpstat command (if not in path)
LPSTAT="/usr/bin/lpstat"
# Ensure known locale
export LC_ALL=C
# Don't change anything below here
# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
if [ ! -x "$LPSTAT" ]
then
echo "UNKNOWN: $LPSTAT not found or is not executable by the nagios user"
exitstatus=$STATE_UNKNOWN
exit $exitstatus
fi
PROGNAME=`basename $0`
print_usage() {
echo "Usage: $PROGNAME -H <hostname> -T <s|b> -w <size warning level> -c <size critical level> -a <max age>"
echo ""
echo "Notes:"
echo "-H: Hostname - Can be a hostname or IP address"
echo "-T: Type of check - Can be queue size (s) or both queu size and queue age (b)"
echo "-w: WARNING level for queue size"
echo "-c: CRITICAL level for queue size"
echo "-a: Max age of queue. Returns CRITICAL if jobs exists older than <max age> days"
echo ""
}
print_help() {
print_usage
echo ""
echo "This plugin will check the CUPS print queue on a remote (or local with -H localhost) CUPS server."
echo "It can check both the size of the queue and the age of the oldest print job in the queue."
echo "-w and -c are for reporting warning and critical levels of the queue size."
echo "-a is optional for specifying the max age of a job in the print queue. Anything older thatn <max age>"
echo "will return a CRITICAL"
echo ""
exit 0
}
check_queue_size()
{
if [ "$JOBCOUNT" -ge "$critlevel" ]
then
MESSAGE="CRITICAL: CUPS queue size - $JOBCOUNT| $PERFDATA"
exitstatus=$STATE_CRITICAL
elif [ "$JOBCOUNT" -ge "$warnlevel" ]
then
MESSAGE="WARNING: CUPS queue size - $JOBCOUNT| $PERFDATA"
exitstatus=$STATE_WARNING
else
MESSAGE="OK: CUPS queue size - $JOBCOUNT| $PERFDATA"
exitstatus=$STATE_OK
fi
}
if [ $# -lt 4 ]; then
print_usage
exit $STATE_UNKNOWN
fi
exitstatus=$STATE_UNKNOWN #default
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
-H)
hostname=$2
shift
;;
-T)
testtype=$2
shift
;;
-w)
warnlevel=$2
shift
;;
-c)
critlevel=$2
shift
;;
-a)
maxage=$2
shift
;;
esac
shift
done
# Check arguments for validity
if [ -z $hostname ]
then
echo "You must specify a hostname (or localhost to test the local system)"
print_usage
exitstatus=$STATE_UNKNOWN
exit $exitstatus
fi
if [[ -z $critlevel || -z $warnlevel ]] # Did we get warn and crit values?
then
echo "You must specify a warning and critical level"
print_usage
exitstatus=$STATE_UNKNOWN
exit $exitstatus
elif [ $critlevel -lt $warnlevel ] # Do the warn/crit values make sense?
then
echo "CRITICAL value of $critlevel is less than WARNING level of $warnlevel"
print_usage
exitstatus=$STATE_UNKNOWN
exit $exitstatus
fi
if [ -z $testtype ] # We require a test type
then
echo "You must specify a test type"
print_usage
exitstatus=$STATE_UNKNOWN
exit $exitstatus
elif [[ "$testtype" = [b]* && -z $maxage ]]
then
echo "You must specify <max age> when using a test type of 'b'"
print_usage
exitstatus=$STATE_UNKNOWN
exit $exitstatus
else
JOBTMP=`mktemp -t lpstat.$hostname.XXXXXX` # Create a tmpfile to store the lpstat results
STALEJOBCOUNT=0 # default number of old jobs
CURDATETS=`date +%s` # Get the current date as unixtime
$LPSTAT -h $hostname -o > $JOBTMP # run the lpstat command against the host.
if [ $? -ne 0 ]
then
rm -rf $JOBTMP
echo "UNKNOWN: lpstat command returned an error. Please test this script manually."
exitstatus=$STATE_UNKNOWN
exit $exitstatus
fi
JOBCOUNT=`wc -l < $JOBTMP` # populate the jobcount
PERFDATA="print_jobs=$JOBCOUNT;$warnlevel;$critlevel;0"
if [[ "$JOBCOUNT" -gt 0 && $maxage ]]
then
MAXAGETS=`echo "86400 * $maxage" | bc` # 86400 seconds in a day * maxage
exec<$JOBTMP # read the file to determine job age
while read PRINTJOB
do
JOBDATE=`echo $PRINTJOB | awk '{ print $4, $5, $6, $7, $8 }'` # Grab the job date from the job listing
JOBDATETS=`date --date="$JOBDATE" +%s` # Convert the job date to unixtime
DATEDIFF=`echo "($CURDATETS - $JOBDATETS)" | bc`
if [ $DATEDIFF -gt $MAXAGETS ]
then
MESSAGE="CRITICAL: Some CUPS jobs are older than $maxage days| $PERFDATA"
exitstatus=$STATE_CRITICAL
else
check_queue_size
fi
done
else
check_queue_size
fi
rm -rf $JOBTMP
fi
echo $MESSAGE
exit $exitstatus
|