Add incidents export, queue alerts, and health summaries
This commit is contained in:
@@ -65,6 +65,10 @@ def _parse_line(line: str) -> tuple[datetime | None, str]:
|
||||
|
||||
|
||||
def read_recent(cfg: dict[str, Any], hours: int, limit: int = 200) -> list[str]:
|
||||
return [f"{dt:%Y-%m-%d %H:%M} {msg}" for dt, msg in read_raw(cfg, hours, limit=limit)]
|
||||
|
||||
|
||||
def read_raw(cfg: dict[str, Any], hours: int, limit: int = 200, *, include_old: bool = False) -> list[tuple[datetime, str]]:
|
||||
path = _get_path(cfg)
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
@@ -74,7 +78,40 @@ def read_recent(cfg: dict[str, Any], hours: int, limit: int = 200) -> list[str]:
|
||||
with open(path, "r", encoding="utf-8", errors="replace") as f:
|
||||
for line in f:
|
||||
dt, msg = _parse_line(line.rstrip())
|
||||
if dt is None or dt < since:
|
||||
if dt is None:
|
||||
continue
|
||||
lines.append(f"{dt:%Y-%m-%d %H:%M} {msg}")
|
||||
if not include_old and dt < since:
|
||||
continue
|
||||
lines.append((dt, msg))
|
||||
return list(lines)
|
||||
|
||||
|
||||
def infer_category(text: str) -> str | None:
|
||||
lower = text.lower()
|
||||
if "category=" in lower:
|
||||
import re
|
||||
|
||||
m = re.search(r"category=([a-z0-9_-]+)", lower)
|
||||
if m:
|
||||
return m.group(1)
|
||||
if "load" in lower:
|
||||
return "load"
|
||||
if "docker" in lower:
|
||||
return "docker"
|
||||
if "restic" in lower or "backup" in lower:
|
||||
return "backup"
|
||||
if "smart" in lower:
|
||||
return "smart"
|
||||
if "ssl" in lower or "cert" in lower:
|
||||
return "ssl"
|
||||
if "npmplus" in lower:
|
||||
return "npmplus"
|
||||
if "gitea" in lower:
|
||||
return "gitea"
|
||||
if "openwrt" in lower:
|
||||
return "openwrt"
|
||||
if "queue" in lower:
|
||||
return "queue"
|
||||
if "selftest" in lower:
|
||||
return "selftest"
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user