From b1f0ca7feccfab3a65a1312325df3060fe637329 Mon Sep 17 00:00:00 2001 From: "David P. Discher" Date: Mon, 27 Jun 2022 20:00:40 +0000 Subject: [PATCH 1/2] Fixes for running under python 3.6 on centos 7. - subprocess.run with the older syntax, - output is also a byte stream that will not json encode, so convert it. --- libpassiveagent/check.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libpassiveagent/check.py b/libpassiveagent/check.py index b883a43..af2b7e2 100644 --- a/libpassiveagent/check.py +++ b/libpassiveagent/check.py @@ -26,7 +26,13 @@ def run_check(c, pc, reschedule_and_post=True): if reschedule_and_post: schedule.reschedule(c, pc) logging.info('run_check(): %s', c['passive checks'][pc]['command'].split()) - res = subprocess.run(c['passive checks'][pc]['command'].split(), capture_output=True, text=True) + if sys.version_info[:3] > (3,7): + res = subprocess.run(c['passive checks'][pc]['command'].split(), capture_output=True, text=True) + else: + from subprocess import PIPE + res = subprocess.run(c['passive checks'][pc]['command'].split(), stdout=PIPE, stderr=PIPE) + stdout_str = res.stdout + res.stdout = stdout_str.decode("utf-8") logging.info('run_check(): returncode: %s; stdout: %s', res.returncode, res.stdout.rstrip()) if reschedule_and_post: post_results(c, pc, { "code": res.returncode, "stdout": res.stdout.rstrip() }) From 86865f6eceee9c7790cf5d07ecc8bd59d30f234a Mon Sep 17 00:00:00 2001 From: "David P. Discher" Date: Mon, 27 Jun 2022 21:07:50 +0000 Subject: [PATCH 2/2] when the nagios end point is down a fatal expection happens, handle this. --- libpassiveagent/check.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libpassiveagent/check.py b/libpassiveagent/check.py index af2b7e2..fdb8d33 100644 --- a/libpassiveagent/check.py +++ b/libpassiveagent/check.py @@ -63,6 +63,8 @@ def post_results(c, pc, res): r = requests.post(u, data=postdata, timeout=10) except requests.Timeout: logging.warning('Timeout posting results to %s', u) + except requests.exceptions.ConnectionError: + logging.warning('Connection Error posting results to %s', u) else: if r.status_code == requests.codes.ok: logging.info('Submitted successfully to NRDP: %s', u)