2to3/manual: check_cups.py

This commit is contained in:
Sven Velt 2020-12-29 22:45:23 +01:00
parent f5bf5494c6
commit a49297eda7

View file

@ -1,8 +1,8 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
##################################################################### #####################################################################
# (c) 2016 by Sven Velt, Germany # # (c) 2016- by Sven Velt, Germany #
# sven-mymonplugins@velt.biz # # sven-mymonplugins@velt.biz #
# # # #
# This file is part of "velt.biz - My Monitoring Plugins" # # This file is part of "velt.biz - My Monitoring Plugins" #
@ -30,19 +30,18 @@ import sys
import time import time
try: try:
from monitoringplugin import MonitoringPlugin from MyMonPlugin import MonitoringPlugin
except ImportError: except ImportError:
print '==========================' print('==========================')
print 'AIKS! Python import error!' print('AIKS! Python import error!')
print '==========================\n' print('==========================\n')
print 'Could not find "monitoringplugin.py"!\n' print('Could not find class "MonitoringPlugin"!\n')
print 'Did you download "%s"' % os.path.basename(sys.argv[0]) print('Did you download "%s"' % os.path.basename(sys.argv[0]))
print 'without "monitoringplugin.py"?\n' print('without "MyMonPlugin/"?\n')
print 'Please go back to' print('Please go back to')
print 'https://gogs.velt.biz/velt.biz/MyMonPlugins and download it,' print('https://gogs.velt.biz/velt.biz/MyMonPlugins and:')
print 'or even better:' print('- get a full archive at http://gogs.velt.biz/velt.biz/MyMonPlugins/releases')
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 'or a master snapshot at http://gogs.velt.biz/velt.biz/MyMonPlugins/archive/master.tar.gz\n'
sys.exit(127) 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('-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('-w', '', 'warn', 'warning thresold for old jobs (seconds)', default='3600')
plugin.add_cmdlineoption('-c', '', 'crit', 'warning thresold for old jobs (seconds)', default='86400') 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): def check_job_queue(output_job_queue):
plugin.verbose(1, 'Checking 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})') 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_warn = []
jobs_crit = [] jobs_crit = []
@ -122,7 +121,7 @@ def check_job_queue(output_job_queue):
continue continue
tstamp = time.strptime(f.group(1), '%a %d %b %Y %I:%M:%S %p %Z') 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 age = nowsecs - tsecs
rc = plugin.value_wc_to_returncode(age, plugin.options.warn, plugin.options.crit) rc = plugin.value_wc_to_returncode(age, plugin.options.warn, plugin.options.crit)
if rc == 1: if rc == 1:
@ -156,7 +155,7 @@ def call_cmd(cmdline):
cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE, env=myenv) cmd = subprocess.Popen(cmdline, stdout=subprocess.PIPE, env=myenv)
(sout, serr) = cmd.communicate() (sout, serr) = cmd.communicate()
if sout: if sout:
sout = sout.lstrip().rstrip().split('\n') sout = sout.lstrip().rstrip().decode('utf-8').split('\n')
else: else:
sout = [] sout = []
except OSError: except OSError: