33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Semantic health for Tier-1: not just port-open."""
|
|
import json, subprocess, urllib.request, os, pathlib
|
|
|
|
def code(url, headers=None, timeout=8):
|
|
try:
|
|
r=urllib.request.Request(url, headers=headers or {})
|
|
with urllib.request.urlopen(r, timeout=timeout) as x:
|
|
return x.status
|
|
except Exception:
|
|
return 0
|
|
|
|
def curl(url, timeout=8):
|
|
try:
|
|
return int(subprocess.run(["curl","-sk","-o","/dev/null","-w","%{http_code}","--max-time",str(timeout),url],capture_output=True,text=True).stdout.strip())
|
|
except Exception:
|
|
return 0
|
|
|
|
checks=[]
|
|
# Immich semantic ping
|
|
immich=curl("http://192.168.1.104:2283/api/server-info/ping")
|
|
checks.append({"service":"immich","code":immich,"status":"ok" if immich==200 else "degraded"})
|
|
# Bazarr API
|
|
bazarr=curl("http://192.168.1.120:6767/")
|
|
checks.append({"service":"bazarr","code":bazarr,"status":"ok" if bazarr in (200,302) else "degraded"})
|
|
# n8n web
|
|
n8n=curl("http://192.168.1.108:5680/")
|
|
checks.append({"service":"n8n","code":n8n,"status":"ok" if n8n==200 else "degraded"})
|
|
# Jellyfin public info
|
|
jf=curl("http://192.168.1.103:8096/System/Info/Public")
|
|
checks.append({"service":"jellyfin","code":jf,"status":"ok" if jf==200 else "degraded"})
|
|
print(json.dumps({"checks":checks,"degraded":sum(1 for c in checks if c["status"]!="ok")},ensure_ascii=False))
|