Skip to content

Commit

Permalink
allow json output fgor monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
baszoetekouw committed Apr 8, 2024
1 parent d8ef190 commit 698e9a1
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions getmonitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sys
import json

# getmonitor.py is used to retrieve the monitor values
# using Zabbix system.run[]
Expand All @@ -8,19 +9,23 @@
def get(env, command):
try:
with open(f'status/{env}.log', 'r') as f:
time = f.readline()
test = f.readline()
login = f.readline()
time = f.readline().strip()
test = f.readline().strip()
login = f.readline().strip()
pam = f.readline().strip()
if command == 'time':
return time.strip()
return time
elif command == 'test':
return test.strip()
return test
elif command == 'login':
return login.strip()
return login
elif command == 'pam':
return login.strip()
except Exception:
return "error\n"
return pam
elif command == 'json':
data = { "time": int(time), "test": test, "login": login, "pam": pam }
return json.dumps(data)
except Exception as e:
return f"error: {e}\n"


if __name__ == '__main__':
Expand Down

0 comments on commit 698e9a1

Please sign in to comment.