"""HTTP reachability checks for critical web services.""" from __future__ import annotations import urllib.request import urllib.error from typing import Any def _http_check(url: str) -> dict[str, Any]: """Returns ok if the URL responds with any 2xx or 3xx status code.""" try: req = urllib.request.Request(url, method="GET") with urllib.request.urlopen(req, timeout=5) as resp: status = resp.status except urllib.error.HTTPError as e: status = e.code except Exception as exc: return {"status": "unreachable", "error": str(exc)} ok = status < 400 return {"status": "ok" if ok else "degraded", "http_code": status} def check_web_services() -> dict[str, Any]: """ Verify that critical web services respond over HTTP. Checks: - Guacamole: login page - Jellyfin: web UI root - Navidrome: web UI root """ return { "guacamole": _http_check("http://localhost:8082/guacamole/"), "jellyfin": _http_check("http://localhost:8096/web/index.html"), "navidrome": _http_check("http://localhost:4533/"), } if __name__ == "__main__": import json print(json.dumps(check_web_services(), indent=4))