Skip to content
Snippets Groups Projects
Select Git revision
  • 103d89664441e690a24c6fc95b582d1becdda2de
  • master default protected
  • 9.0
  • 8.0
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • nt-tools
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
  • v8.0.1982
  • v8.0.1980
  • v8.0.1978
  • v8.0.1976
  • v8.0.1974
  • v8.0.1972
  • v8.0.1970
  • v8.0.1968
  • v8.0.1966
41 results

Program.pmod

Blame
  • 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])