#!/usr/bin/env python3 """logwatch.py OUTDIR — every 10 min, copy the box's own log ring (the „Hibakeresés" page's data: controller INFO+ and the host agent's lines) and append the NEW lines to OUTDIR/controller.log and OUTDIR/agent.log. Read-only. A night restart erases the ring; this keeps the night's evidence off the box (rule 5). Run under sec (dashboard password).""" import json, os, sys, time sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))); import ctl out = sys.argv[1]; os.makedirs(out, exist_ok=True) seen = {"c": set(), "a": set()} while True: for key, path, fn in (("c", "/api/debug/logs?level=INFO", "controller.log"), ("a", "/api/debug/agent-logs", "agent.log")): try: c, d = ctl.call("GET", path, timeout=60) new = 0 with open(os.path.join(out, fn), "a") as f: for e in (d.get("data") or {}).get("entries") or []: k = (e.get("timestamp"), e.get("message")) if k not in seen[key]: seen[key].add(k); new += 1 f.write(f"{e.get('timestamp')} {e.get('level')} {e.get('message')}\n") print(time.strftime("%H:%M:%SZ", time.gmtime()), fn, "http", c, "new", new, flush=True) except Exception as ex: # noqa: BLE001 print(time.strftime("%H:%M:%SZ", time.gmtime()), fn, "NO ANSWER", type(ex).__name__, flush=True) time.sleep(600)