"README" did not exist on "nt-tools"
Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authoredNiels Möller authored
check_cups 1.88 KiB
#!/usr/bin/env python
#
# Check that the oldest entry in the CUPS queue is new enough.
#
# Usage: check_cups queue
#
# This check script is maintained in a Subversion repository at
# http://lsvn.lysator.liu.se/svnroot/nagios-plugins. Contact
# <ceder@lysator.liu.se> for commit access.
import os
import sys
import time
TIME_FORMATS = [
"%a %b %d %H:%M:%S %Y",
"%a %d %b %Y %H:%M:%S %p %Z",
]
def check_queue(host, queue):
now = time.time()
worst_age = 0
worst_user = None
ctr = 0
bad_time = False
if host is None:
fd = os.popen("lpstat -o %s" % (queue, ))
else:
fd = os.popen("lpstat -h %s -o %s" % (host, queue))
for line in fd:
ctr = ctr + 1
qid, who, size, when = line.strip().split(None, 3)
age = None
for fmt in TIME_FORMATS:
try:
age = now - time.mktime(time.strptime(when, fmt))
except ValueError:
pass
if age is not None:
break
if age is None:
bad_time = True
elif age > worst_age:
worst_age = age
worst_user = who
if fd.close():
print "UNKNOWN - bad exit status from lpstat"
sys.exit(3)
if worst_age > 120 * 60:
print "CRITICAL - %d jobs, %.1f minutes, oldest %s" % (
ctr, worst_age/60, worst_user)
sys.exit(2)
elif worst_age > 15 * 60:
print "WARNING - %d jobs, %.1f minutes, oldest %s" % (
ctr, worst_age/60, worst_user)
sys.exit(1)
elif bad_time:
print "UNKNOWN - bad time format. %d jobs in queue" % (ctr, )
sys.exit(3)
elif ctr == 0:
print "OK - empty queue"
sys.exit(0)
else:
print "OK - %d jobs in queue, oldest is %.1f seconds old" % (
ctr, worst_age)
sys.exit(0)
if __name__ == '__main__':
if len(sys.argv) == 2:
check_queue(None, sys.argv[1])
else:
check_queue(sys.argv[1], sys.argv[2])