diff --git a/libpassiveagent/check.py b/libpassiveagent/check.py index b883a43..fdb8d33 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() }) @@ -57,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)