Fix SMS signal quality getting; new remote host notifications for Icinga
This commit is contained in:
parent
6cdfa96267
commit
4c3b7612e0
32
icinga_host_notify_remote.py
Executable file
32
icinga_host_notify_remote.py
Executable file
@ -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()
|
@ -101,7 +101,7 @@ def send_sms(recipients, smsstring):
|
|||||||
|
|
||||||
while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]:
|
while not modem.GetStatus().get('signal-quality', None) or not modem.GetStatus()['signal-quality'][1]:
|
||||||
modem = get_modem()
|
modem = get_modem()
|
||||||
print(modem.GetStatus()['signal-quality'])
|
print(modem.GetStatus().get('signal-quality', None))
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
for line in recipients:
|
for line in recipients:
|
||||||
|
Loading…
Reference in New Issue
Block a user