feat: health endpoint shows both bot statuses and inbox state

Shows MCP bridge status, homelab bot active/inactive, inbox
pending lines, and message stats.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mikkel Georgsen 2026-03-30 13:01:48 +00:00
parent a7344fa332
commit 6fcc000c39

View file

@ -199,9 +199,33 @@ async def ingest_message(request: Request) -> JSONResponse:
async def health(request: Request) -> JSONResponse:
"""Health check endpoint."""
"""Health check endpoint with both bot statuses."""
from pathlib import Path
import subprocess as sp
status = db.get_status()
return JSONResponse({"status": "ok", **status})
# Check homelab bot inbox
inbox_path = Path.home() / "homelab" / "telegram" / "inbox"
inbox_size = inbox_path.stat().st_size if inbox_path.exists() else 0
inbox_lines = len(inbox_path.read_text().splitlines()) if inbox_size > 0 else 0
# Check both services
mcp_active = True # We're running if this responds
try:
result = sp.run(["systemctl", "--user", "is-active", "telegram-bot"],
capture_output=True, text=True, timeout=2)
homelab_bot_active = result.stdout.strip() == "active"
except Exception:
homelab_bot_active = False
return JSONResponse({
"status": "ok",
"mcp_bridge": {"active": mcp_active, "telegram_polling": True},
"homelab_bot": {"active": homelab_bot_active},
"inbox": {"pending_lines": inbox_lines, "bytes": inbox_size},
**status,
})
custom_routes = [