diff --git a/check_cups b/check_cups index fa6eae0dda760aaeb8e727d70ae3c37509231024..95d5ff2eaad08af9ec7efaaff8341cb720ccdbda 100755 --- a/check_cups +++ b/check_cups @@ -12,11 +12,17 @@ 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, )) @@ -25,8 +31,17 @@ def check_queue(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")) - if age > worst_age: + 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 @@ -42,6 +57,9 @@ def check_queue(host, queue): 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)