From 4c3b7612e0de0e76fd0117f902213dbaab4da288 Mon Sep 17 00:00:00 2001 From: Pavel Valach Date: Sat, 1 Aug 2020 14:57:54 +0000 Subject: [PATCH] Fix SMS signal quality getting; new remote host notifications for Icinga --- icinga_host_notify_remote.py | 32 ++++++++++++++++++++++++++++++++ sms_functions.py | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 icinga_host_notify_remote.py diff --git a/icinga_host_notify_remote.py b/icinga_host_notify_remote.py new file mode 100755 index 0000000..b5816ce --- /dev/null +++ b/icinga_host_notify_remote.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +import logging +import os +import sys +import subprocess +from icinga_host_notify import assemble_sms +import sms_functions + +def main(): + sms_msg = assemble_sms() + sms_number = os.environ.get('USERMOBILE') + logger.info("Remote - Sending SMS to %s: %s", sms_number, sms_msg) + + hostname = sys.argv[1] + + success = False + retries = 0 + max_retries = 3 + + while not success and retries < max_retries: + retries += 1 + try: + # Contact remote host + subprocess.run([ '/usr/bin/ssh', hostname, '/opt/sms/send_sms.py', sms_msg, sms_number ], check=True) + except: + raise + else: + success = True + +if __name__ == "__main__": + main() diff --git a/sms_functions.py b/sms_functions.py index 90d2b24..3834b35 100644 --- a/sms_functions.py +++ b/sms_functions.py @@ -101,7 +101,7 @@ def send_sms(recipients, smsstring): while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]: modem = get_modem() - print(modem.GetStatus()['signal-quality']) + print(modem.GetStatus().get('signal-quality', None)) time.sleep(2) for line in recipients: