From 76120d5ca1861519a0811914d9d586ef714434ee Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Sat, 6 Jan 2007 11:43:38 +0000 Subject: [PATCH] Check the return value of lpstat and report UNKNOWN if it is non-zero. New argument: hostname whose queue should be checked. --- check_cups | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/check_cups b/check_cups index e484617..52cf87c 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]) -- GitLab