From 6fb1532b3316ffeee37ec1eeda83d6c5b97c8d8e Mon Sep 17 00:00:00 2001 From: Michael Howe Date: Tue, 21 Dec 2021 10:07:42 +0000 Subject: [PATCH] Update server plugins to be python3 compatible --- debian/changelog | 6 ++++++ debian/control | 5 ++--- plugins/check_owntracks | 14 +++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index fff8674..6db3572 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +nagios-plugins-local (0.24) unstable; urgency=medium + + * Update nagios-plugins-local-server checks to support python3 + + -- Michael Howe Tue, 21 Dec 2021 10:07:23 +0000 + nagios-plugins-local (0.23) unstable; urgency=medium * Fix postrm diff --git a/debian/control b/debian/control index 72eeaf1..5ebadaa 100644 --- a/debian/control +++ b/debian/control @@ -17,14 +17,13 @@ Package: nagios-plugins-local-server Architecture: any Depends: ${misc:Depends}, perl, - python, + python3, libc6, libnet-telnet-perl, libregexp-common-perl, libauthen-krb5-perl, nagios-plugins-local-client (= ${source:Version}) - , python-requests -# check_mqtt + , python3-requests , python3-paho-mqtt Breaks: nagios-plugins-local (<0.11) Description: Local nagios plugins diff --git a/plugins/check_owntracks b/plugins/check_owntracks index 81ca821..e10020b 100755 --- a/plugins/check_owntracks +++ b/plugins/check_owntracks @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # From @@ -24,9 +24,9 @@ __license__ = 'MIT' parser = argparse.ArgumentParser() parser.add_argument('-M', '--mqtt-hostname', metavar='', help='mqtt host to connect to (defaults to localhost)', dest='mqtt_hostname', default='localhost') -parser.add_argument('-P', '--mqtt-port', metavar='', help='mqtt port to connect to (defaults to 1883)', dest='mqtt_port', default=1883) +parser.add_argument('-P', '--mqtt-port', metavar='', help='mqtt port to connect to (defaults to 1883)', dest='mqtt_port', default=1883, type=int) parser.add_argument('-H', '--recorder-hostname', metavar='', help='recorder host to connect to (defaults to localhost)', dest='recorder_hostname', default='localhost') -parser.add_argument('-p', '--recorder-port', metavar='', help='recorder port to connect to (defaults to 8083)', dest='recorder_port', default='8083') +parser.add_argument('-p', '--recorder-port', metavar='', help='recorder port to connect to (defaults to 8083)', dest='recorder_port', default='8083', type=int) parser.add_argument('-U', '--recorder-url', metavar='', help='url path to recorder (defaults to /)', dest='recorder_url', default='/') parser.add_argument('-r', '--recorder-protocol', metavar='', help='protocol to access recorder (defaults to http)', dest='recorder_protocol', default='http') parser.add_argument('-u', '--username', metavar='', help='mqtt username to use (defaults to none)', dest='username', default=None) @@ -95,7 +95,7 @@ def pingping(tics): auth=auth, tls=tls, **params) - except Exception, e: + except Exception as e: status = CRITICAL msg = msg + " mqtt failed: " + str(e) @@ -113,7 +113,7 @@ def check_response(url, tics): try: r = requests.post(url + "/api/0/last", params= { 'user' : 'ping', 'device' : 'ping' }) data = json.loads(r.text)[0] # Return is an array - except Exception, e: + except Exception as e: return CRITICAL, "check_response failed: " + str(e) tst = data['tst'] @@ -132,7 +132,7 @@ if __name__ == '__main__': status, msg = pingping(tics) if status != OK: - print "%s ot-recorder pingping failed: %s" % (codes[status], msg) + print("%s ot-recorder pingping failed: %s" % (codes[status], msg)) sys.exit(status) # pause for a moment to give mqtt a chance to catch up @@ -141,6 +141,6 @@ if __name__ == '__main__': recorder_full_url = "%s://%s:%s%s" % ( args.recorder_protocol, args.recorder_hostname, args.recorder_port, args.recorder_url ) status, msg = check_response(recorder_full_url, tics) - print "%s %s" % (codes[status], msg) + print("%s %s" % (codes[status], msg)) sys.exit(status) -- 2.39.5