Skip to content

Commit ad48dfa

Browse files
committedNov 29, 2023
remote-monitor: add a simple service which checks if NIPA is running
Add a script which can be run on a laptop or such, which fetches the status of NIPA from remote URL (the json which NIPA renders) and shows a pop up when something fails. Status for netdev can be fetched from: https://netdev.bots.linux.dev/static/nipa/systemd.json the script takes the URL as the first (and only) arg. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c4724f9 commit ad48dfa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 

‎remote-monitor.py

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

0 commit comments

Comments
 (0)
Please sign in to comment.