-
Notifications
You must be signed in to change notification settings - Fork 8
/
remote-monitor.py
executable file
·41 lines (32 loc) · 1.07 KB
/
remote-monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
import json
import os
import requests
import subprocess
import time
def notify(hdr: str, msg: str) -> None:
subprocess.check_output(["notify-send", hdr, msg])
def main() -> None:
while True:
try:
r = requests.get(os.sys.argv[1])
js = json.loads(r.content.decode('utf-8'))
good = 0
bad = []
for name in js["services"]:
s = js["services"][name]
if s["ActiveState"] == "active" and s["SubState"] == "running":
good += 1
elif isinstance(s.get("TriggeredBy", 0), str) and s["Result"] == "success":
good += 1
else:
bad.append(name)
if bad:
notify("NIPA", f"Services in bad state: {bad} (good cnt: {good})")
except Exception:
notify("NIPA", "checking status failed")
raise
time.sleep(30)
if __name__ == "__main__":
main()