51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import time
|
|
import urllib.error
|
|
import urllib.request
|
|
from pathlib import Path
|
|
import psycopg2
|
|
|
|
PASS = Path("/root/.pg-superuser-pass").read_text().strip()
|
|
conn = psycopg2.connect(host="192.168.1.151", dbname="rag", user="postgres", password=PASS, client_encoding="UTF8")
|
|
cur = conn.cursor()
|
|
|
|
CHECKS = [
|
|
("gitea", "http://192.168.1.140:3000/api/v1/version", {200}),
|
|
("authentik", "http://192.168.1.114:9000/-/health/live/", {200}),
|
|
("matrix", "http://192.168.1.155:8008/_matrix/client/versions", {200}),
|
|
("prism", "http://127.0.0.1:8095/api/health", {200}),
|
|
("audit360", "http://127.0.0.1:9160/health", {200}),
|
|
("mealie", "http://192.168.1.110:9925/api/app/about", {200}),
|
|
("seerr", "http://192.168.1.121:5055/api/v1/status", {200}),
|
|
("paperless", "http://192.168.1.105:8000/api/", {200, 302}),
|
|
]
|
|
|
|
for name, url, accept in CHECKS:
|
|
ok = False
|
|
status = None
|
|
err = None
|
|
t0 = time.time()
|
|
try:
|
|
with urllib.request.urlopen(url, timeout=6) as r:
|
|
status = r.status
|
|
r.read(256)
|
|
ok = status in accept
|
|
if not ok:
|
|
err = "unexpected status %s" % status
|
|
except urllib.error.HTTPError as e:
|
|
status = e.code
|
|
ok = status in accept
|
|
if not ok:
|
|
err = "HTTP %s" % status
|
|
except Exception as e:
|
|
err = str(e)[:200]
|
|
latency = int((time.time() - t0) * 1000)
|
|
cur.execute("""insert into audit.semantic_checks(name,url,status,ok,latency_ms,error)
|
|
values(%s,%s,%s,%s,%s,%s)""", (name, url, status, ok, latency, err))
|
|
print(("OK " if ok else "FAIL "), name, status, latency, err or "", flush=True)
|
|
# retention 7 days
|
|
cur.execute("delete from audit.semantic_checks where checked_at < now()-interval '7 days'")
|
|
conn.commit()
|
|
cur.close(); conn.close()
|