diff --git a/check_cups.py b/check_cups.py index 08fe8e4..e8212d0 100755 --- a/check_cups.py +++ b/check_cups.py @@ -1,8 +1,8 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- encoding: utf-8 -*- ##################################################################### -# (c) 2016 by Sven Velt, Germany # +# (c) 2016- by Sven Velt, Germany # # sven-mymonplugins@velt.biz # # # # This file is part of "velt.biz - My Monitoring Plugins" # @@ -30,19 +30,18 @@ import sys import time try: - from monitoringplugin import MonitoringPlugin + from MyMonPlugin import MonitoringPlugin except ImportError: - print '==========================' - print 'AIKS! Python import error!' - print '==========================\n' - print 'Could not find "monitoringplugin.py"!\n' - print 'Did you download "%s"' % os.path.basename(sys.argv[0]) - print 'without "monitoringplugin.py"?\n' - print 'Please go back to' - print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,' - print 'or even better:' - print 'get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases' - print 'or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n' + print('==========================') + print('AIKS! Python import error!') + print('==========================\n') + print('Could not find class "MonitoringPlugin"!\n') + print('Did you download "%s"' % os.path.basename(sys.argv[0])) + print('without "MyMonPlugin/"?\n') + print('Please go back to') + print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:') + print('- get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases') + print('- or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n') sys.exit(127) @@ -54,7 +53,7 @@ plugin = MonitoringPlugin( ) -plugin.add_cmdlineoption('-P', '--check-printers', 'check_printers', 'check printer queue', default=False, action='store_true' ) +plugin.add_cmdlineoption('-P', '--check-printers', 'check_printers', 'check printer', default=False, action='store_true' ) plugin.add_cmdlineoption('-J', '--check-jobs', 'check_jobs', 'check job queue', default=False, action='store_true') plugin.add_cmdlineoption('-w', '', 'warn', 'warning thresold for old jobs (seconds)', default='3600') plugin.add_cmdlineoption('-c', '', 'crit', 'warning thresold for old jobs (seconds)', default='86400') @@ -110,7 +109,7 @@ def check_printer_queue(output_printer_queue): def check_job_queue(output_job_queue): plugin.verbose(1, 'Checking job queue') m = re.compile('(\w{3} \d\d \w{3} \d{4} \d\d:\d\d:\d\d (AM|PM) \w{3,5})') - nowsecs = long( time.time() ) + nowsecs = int( time.time() ) jobs_warn = [] jobs_crit = [] @@ -122,7 +121,7 @@ def check_job_queue(output_job_queue): continue tstamp = time.strptime(f.group(1), '%a %d %b %Y %I:%M:%S %p %Z') - tsecs = long( time.mktime(tstamp) ) + tsecs = int( time.mktime(tstamp) ) age = nowsecs - tsecs rc = plugin.value_wc_to_returncode(age, plugin.options.warn, plugin.options.crit) if rc == 1: @@ -156,7 +155,7 @@ def call_cmd(cmdline): cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE, env=myenv) (sout, serr) = cmd.communicate() if sout: - sout = sout.lstrip().rstrip().split('\n') + sout = sout.lstrip().rstrip().decode('utf-8').split('\n') else: sout = [] except OSError: @@ -170,7 +169,7 @@ allchecks = not( plugin.options.check_printers or plugin.options.check_jobs ) if allchecks or plugin.options.check_printers: (sout, serr, retcode) = call_cmd(['lpstat', '-a']) check_printer_queue(sout) -if allchecks or plugin.options.check_jobs: +if allchecks or plugin.options.check_jobs: (sout, serr, retcode) = call_cmd(['lpstat', '-o']) check_job_queue(sout)