summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
authorJannik Schönartz2019-04-04 17:21:12 +0200
committerJannik Schönartz2019-04-04 17:21:12 +0200
commitb7e21c617453e89c13ebb24ebb00d96ebba554ce (patch)
tree58d955d47f5132ee314138f8f5381bd2f92a00ce /main.py
parentThrift: Verify SSL cert (diff)
downloadbwlp-monitoring-b7e21c617453e89c13ebb24ebb00d96ebba554ce.tar.gz
bwlp-monitoring-b7e21c617453e89c13ebb24ebb00d96ebba554ce.tar.xz
bwlp-monitoring-b7e21c617453e89c13ebb24ebb00d96ebba554ce.zip
Ping requests now consideres the exitcode of the subprocess
removed config file and add template.
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/main.py b/main.py
index d685b7c..a719fc6 100755
--- a/main.py
+++ b/main.py
@@ -68,13 +68,19 @@ def ping(name, hostname):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
+ response.wait()
+ exit_code = response.returncode
response = response.communicate()
error = response[1].decode('utf-8')
-
# Error happend
- if error != '':
+ if error != '' or exit_code != 0:
+ err_msg = ''
+ if exit_code == 1:
+ err_msg = 'Destination Host Unreachable'
+ elif exit_code == 2:
+ err_msg = error.rstrip()
print('\033[91m' + 'error' + '\033[0m')
- statusList.append(Status(name, hostname, 'error', 'Offline', 'ping', error.rstrip()))
+ statusList.append(Status(name, hostname, 'error', 'Offline', 'ping', err_msg))
else:
print('\033[92m' + 'success' + '\033[0m')
statusList.append(Status(name, hostname, 'success', 'Online', 'ping'))