diff --git a/check_cups b/check_cups index e4846171f8245a97e7a38b84d138c476d98ab47d..52cf87c6043f46f2ac8392d2aece28bbc9b284fc 100755 --- a/check_cups +++ b/check_cups @@ -12,13 +12,14 @@ import os import sys import time -def check_queue(queue): +def check_queue(host, queue): now = time.time() worst_age = 0 worst_user = None ctr = 0 - for line in os.popen("lpstat -o %s" % queue): + 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 = now - time.mktime(time.strptime(when, "%a %b %d %H:%M:%S %Y")) @@ -26,6 +27,10 @@ def check_queue(queue): 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) @@ -44,4 +49,4 @@ def check_queue(queue): if __name__ == '__main__': - check_queue(sys.argv[1]) + check_queue(sys.argv[1], sys.argv[2])