daily-briefing/server/routers/servers.py
Sam c6db0ab569 refactor: replace GraphQL/REST with MQTT-only for Unraid server data
All server stats (CPU, RAM, Docker, shares, disks, array) now come
directly from MQTT topics published by the Unraid MQTT Agent. This
eliminates the need for API keys, HTTP polling, and the GraphQL/REST
fallback chain.

- Rewrote unraid_service.py to read from MQTT store (no httpx needed)
- Simplified servers router (no cache, no enrichment hack)
- Added mqtt_prefix field to UnraidServer config
- Updated DB: both Daddelolymp and Adriahub with mqtt_prefix, no api_key
- Data is always fresh (MQTT pushes every ~15s)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 23:25:57 +01:00

51 lines
1.4 KiB
Python

"""Unraid servers status router — MQTT-only data source."""
from __future__ import annotations
import logging
from typing import Any, Dict, List
from fastapi import APIRouter
from server.config import get_settings
from server.services.mqtt_service import mqtt_service
from server.services.unraid_service import ServerConfig, fetch_all_servers_mqtt
logger = logging.getLogger(__name__)
router = APIRouter(prefix="/api", tags=["servers"])
@router.get("/servers")
async def get_servers() -> Dict[str, Any]:
"""Return status information for all configured Unraid servers.
All data comes from the MQTT message store — no HTTP polling,
no API keys, no cache needed (MQTT data is always fresh).
"""
settings = get_settings()
server_configs: List[ServerConfig] = [
ServerConfig(
name=srv.name,
host=srv.host,
mqtt_prefix=getattr(srv, "mqtt_prefix", "") or srv.name,
)
for srv in settings.unraid_servers
]
if not server_configs:
return {"servers": []}
try:
servers_data = fetch_all_servers_mqtt(server_configs, mqtt_service.store)
except Exception as exc:
logger.exception("Failed to read Unraid server data from MQTT")
return {
"servers": [],
"error": True,
"message": str(exc),
}
return {"servers": servers_data}