diff --git a/check_cups b/check_cups new file mode 100755 index 0000000000000000000000000000000000000000..b5cab92b7dd8f426836788b4870fc5cca40df211 --- /dev/null +++ b/check_cups @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# +# Check that the oldest entry in the CUPS queue is new enough. +# +# Usage: check_cups queue + +import os +import time + +def check_queue(queue): + now = time.time() + worst_age = 0 + worst_user = None + ctr = 0 + + for line in os.popen("lpstat -o %s" % queue): + 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: + worst_age = age + worst_user = who + + if worst_age > 300: + print "CRITICAL - %d jobs, %.1f minutes, oldest %s" % ( + ctr, worst_age/60, worst_user) + sys.exit(2) + elif worst_age > 60: + print "WARNING - %d jobs, %.1f minutes, oldest %s" % ( + ctr, worst_age/60, worst_user) + sys.exit(1) + 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__': + import sys + check_queue(sys.argv[1]) diff --git a/check_saned b/check_saned new file mode 100755 index 0000000000000000000000000000000000000000..362f0c8744b03fc869960dfd3e886fca16b5adc4 --- /dev/null +++ b/check_saned @@ -0,0 +1,32 @@ +#!/bin/sh +# +# usage: check_saned pattern +# +# This script will run "scanimage -L" and grep for the supplied pattern. +# +# FIXME: since scanners in use are not included in the list produced +# by "scanimage -L", the state should be OK if the scanner was seen +# within the last hour, and WARNING if it was seen within the last +# day. + +TMPFILE=`tempfile` +scanimage -L > $TMPFILE 2>&1 +if [ $? -ne 0 ] +then + echo CRITICAL - scanimage failed - "`cat /tmp/scanimage.$$`" + rm $TMPFILE + exit 2 +fi + +grep "$1" $TMPFILE >/dev/null 2>&1 +RC=$? + +if [ $RC -ne 0 ] +then + echo CRITICAL - scanner not found + rm $TMPFILE + exit 2 +fi +rm $TMPFILE +echo OK - all fine +exit 0