"""T0/T1 checks — Spec 029.""" from __future__ import annotations import os import sqlite3 import time import httpx DESK = os.getenv("DESK_PUBLIC_URL", "https://desk.ligbox.com.br") VM112 = os.getenv("VM112_API_URL", "http://10.10.10.112:8090") WIZARD = os.getenv("WIZARD_ONBOARD_URL", "https://onboard.ligbox.com.br/onboard") PFS_URL = os.getenv("PFSENSE_API_URL", "https://firewall.itecnologys.com/api/v2/status/system") PFS_USER = os.getenv("PFSENSE_API_USER", "api_cursor") PFS_PASS = os.getenv("PFSENSE_API_PASSWORD", "805353") PVE = os.getenv("PVE_API_URL", "https://10.10.10.2:8006/api2/json") PVE_USER = os.getenv("PVE_USER", "root@pam") PVE_PASS = os.getenv("PVE_PASSWORD", "") PVE_NODE = os.getenv("PVE_NODE", "big1") VMIDS = [int(x) for x in os.getenv("AGENTIC_CRITICAL_VMIDS", "112,122,123,104").split(",") if x.strip()] OLLAMA = os.getenv("OLLAMA_BASE_URL", "http://10.10.10.123:11434").rstrip("/") VM123_IP = os.getenv("VM123_IP", "10.10.10.123") OPENPANEL_BRIDGE = os.getenv("OPENPANEL_BRIDGE_URL", f"http://{VM123_IP}:18087").rstrip("/") def _http(url, *, auth=None, max_ms=2500): t0 = time.perf_counter() try: with httpx.Client(timeout=15, verify=False, follow_redirects=True) as c: r = c.get(url, auth=auth) ms = int((time.perf_counter() - t0) * 1000) return {"ok": r.status_code == 200 and ms <= max_ms, "status_code": r.status_code, "latency_ms": ms, "url": url} except Exception as e: return {"ok": False, "error": str(e), "url": url} def check_desk_api_health(): r = _http(f"{DESK}/api/health", max_ms=4000) return [] if r["ok"] else [ { "severity": "high", "category": "api", "title": "Desk API health falhou", "detail_md": str(r), "evidence": r, "human_action": "Verificar docker-compose api VM122", } ] def check_vm112_health(): out = [] r1 = _http(f"{VM112}/api/onboarding/health") if not r1["ok"]: out.append( { "severity": "high", "category": "api", "title": "VM112 API down", "detail_md": str(r1), "evidence": r1, "human_action": "systemctl ligbox-wizard VM112", } ) r2 = _http(WIZARD, max_ms=4000) if not r2["ok"]: out.append( { "severity": "warn", "category": "api", "title": "Portal /onboard falhou", "detail_md": str(r2), "evidence": r2, "human_action": "Traefik CT114 + VM112", } ) return out def check_pfsense_api(): r = _http(PFS_URL, auth=(PFS_USER, PFS_PASS), max_ms=4000) return [] if r["ok"] else [ { "severity": "warn", "category": "infra", "title": "pfSense API falhou", "detail_md": str(r), "evidence": r, "human_action": "Validar firewall.itecnologys.com via Traefik", } ] def check_funnel_stuck(conn, max_stuck=5): try: c = conn.execute( "SELECT COUNT(*) n FROM tickets WHERE status IN ('open','assisting','escalated') " "AND (subject LIKE '%onboarding%' OR payload LIKE '%onboarding%') " "AND datetime(created_at)