Files
weval-l99/health-monitor.py
2026-04-13 12:43:21 +02:00

38 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""WEVAL Health Monitor — replaces n8n workflow
Checks registry, alerts Mattermost if issues found.
Cron: */30 * * * *
"""
import json, urllib.request
REG = "https://weval-consulting.com/api/registry.php"
MM = "http://localhost:8065/hooks/pt54hzthf3b6pe6rgp1ionipnh"
try:
d = json.loads(urllib.request.urlopen(REG, timeout=10).read())
except:
d = None
if not d:
msg = "Registry unreachable"
else:
issues = []
nr = d.get("tests", {}).get("nonreg", {})
if nr and nr.get("pass", 0) < nr.get("total", 999):
issues.append(f"NonReg {nr['pass']}/{nr['total']}")
disk = d.get("infrastructure", {}).get("disk_pct", "0%")
if int(disk.replace("%", "") or 0) > 90:
issues.append(f"Disk {disk}")
ag = d.get("agents", {})
if ag.get("total", 0) < 600:
issues.append(f"Agents low: {ag.get('total')}")
msg = " | ".join(issues) if issues else None
if msg:
body = json.dumps({"text": f":warning: WEVAL Health: {msg}"}).encode()
req = urllib.request.Request(MM, data=body, headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req, timeout=5)
except:
pass