96 lines
3.4 KiB
Python
96 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Sovereign Claude 2 — Autonomous system health check & report"""
|
|
import json, os, ssl, subprocess, urllib.request, time
|
|
from datetime import datetime
|
|
|
|
ssl._create_default_https_context = ssl._create_unverified_context
|
|
|
|
OLLAMA = "http://127.0.0.1:11434"
|
|
MATTERMOST = "http://localhost:8065/hooks/pt54hzthf3b6pe6rgp1ionipnh"
|
|
|
|
def log(msg):
|
|
print(f"[{datetime.now().strftime('%H:%M:%S')}] {msg}")
|
|
|
|
def main():
|
|
log("=" * 50)
|
|
log("SOVEREIGN CLAUDE 2 v2.0 — Clean rewrite")
|
|
log("=" * 50)
|
|
|
|
# 1. Load directives
|
|
directives = ""
|
|
for f in ["/opt/wevads/vault/claude2-mission-4avr.md", "/var/www/html/api/claude2-mission.md"]:
|
|
if os.path.exists(f):
|
|
directives = open(f).read()[:3000]
|
|
break
|
|
log(f"Directives loaded: {len(directives)} chars")
|
|
|
|
# 2. Get registry via PHP CLI (bypasses nginx+Authentik)
|
|
registry = None
|
|
try:
|
|
r = subprocess.run(["php", "/opt/weval-l99/registry-local.php"],
|
|
capture_output=True, text=True, timeout=30)
|
|
raw = r.stdout.strip() if r.stdout else ""
|
|
if raw:
|
|
parsed = json.loads(raw)
|
|
if isinstance(parsed, dict):
|
|
registry = parsed
|
|
elif isinstance(parsed, list):
|
|
registry = {"data": parsed}
|
|
except Exception as e:
|
|
log(f"Registry error: {e}")
|
|
|
|
if registry:
|
|
try:
|
|
agents = registry.get("agents", {}).get("total", "?")
|
|
log(f"Registry: {agents} agents")
|
|
except:
|
|
log("Registry parsed but unreadable")
|
|
else:
|
|
log("Registry unavailable")
|
|
|
|
# 3. Build report
|
|
report = f"Sovereign Claude 2 Report — {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
|
|
if registry and isinstance(registry, dict):
|
|
try:
|
|
report += f"Agents: {registry.get('agents', {}).get('total', '?')}\n"
|
|
except:
|
|
pass
|
|
try:
|
|
nr = registry.get("tests", {}).get("nonreg", {})
|
|
if isinstance(nr, dict):
|
|
report += f"NonReg: {nr.get('pass', '?')}/{nr.get('total', '?')}\n"
|
|
except:
|
|
pass
|
|
|
|
# 4. Try Ollama for analysis
|
|
try:
|
|
prompt = f"Tu es un DevOps WEVAL. Status: {json.dumps(registry)[:500] if registry else 'unknown'}. Donne 3 actions prioritaires."
|
|
data = json.dumps({"model": "weval-brain-v3", "prompt": prompt, "stream": False}).encode()
|
|
req = urllib.request.Request(f"{OLLAMA}/api/generate", data,
|
|
headers={"Content-Type": "application/json"})
|
|
resp = urllib.request.urlopen(req, timeout=60)
|
|
result = json.loads(resp.read())
|
|
analysis = result.get("response", "")[:500]
|
|
report += f"\nAnalysis: {analysis}\n"
|
|
log(f"Ollama analysis: {len(analysis)} chars")
|
|
except Exception as e:
|
|
log(f"Sovereign error: {e}")
|
|
report += f"\nOllama unavailable: {e}\n"
|
|
|
|
# 5. Send to Mattermost
|
|
try:
|
|
mm_data = json.dumps({"text": report}).encode()
|
|
req = urllib.request.Request(MATTERMOST, mm_data,
|
|
headers={"Content-Type": "application/json"})
|
|
urllib.request.urlopen(req, timeout=10)
|
|
log("Report sent to Mattermost")
|
|
except Exception as e:
|
|
log(f"Mattermost error: {e}")
|
|
|
|
log("DONE")
|
|
|
|
try:
|
|
main()
|
|
except Exception as e:
|
|
print(f"SOVEREIGN CRASHED: {e}")
|