2026-03-02 01:48:51 +01:00
|
|
|
"""Unraid servers status router."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter
|
|
|
|
|
|
|
|
|
|
from server.cache import cache
|
feat: add Admin Panel with JWT auth, DB settings, and integration management
Complete admin backend with login, where all integrations (weather, news,
Home Assistant, Vikunja, Unraid, MQTT) can be configured via web UI instead
of ENV variables. Two-layer config: ENV seeds DB on first start, then DB
is source of truth. Auto-migration system on startup.
Backend: db.py shared pool, auth.py JWT, settings_service CRUD, seed_service,
admin router (protected), test_connections per integration, config.py rewrite.
Frontend: react-router v6, login page, admin layout with sidebar, 8 settings
pages (General, Weather, News, HA, Vikunja, Unraid, MQTT, ChangePassword),
shared IntegrationForm + TestButton components.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 10:37:30 +01:00
|
|
|
from server.config import get_settings
|
2026-03-02 01:48:51 +01:00
|
|
|
from server.services.unraid_service import ServerConfig, fetch_all_servers
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api", tags=["servers"])
|
|
|
|
|
|
|
|
|
|
CACHE_KEY = "servers"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/servers")
|
|
|
|
|
async def get_servers() -> Dict[str, Any]:
|
|
|
|
|
"""Return status information for all configured Unraid servers.
|
|
|
|
|
|
|
|
|
|
Response shape::
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"servers": [ ... server dicts ... ]
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# --- cache hit? -----------------------------------------------------------
|
|
|
|
|
cached = await cache.get(CACHE_KEY)
|
|
|
|
|
if cached is not None:
|
|
|
|
|
return cached
|
|
|
|
|
|
|
|
|
|
# --- cache miss -----------------------------------------------------------
|
|
|
|
|
server_configs: List[ServerConfig] = [
|
|
|
|
|
ServerConfig(
|
|
|
|
|
name=srv.name,
|
|
|
|
|
host=srv.host,
|
|
|
|
|
api_key=srv.api_key,
|
|
|
|
|
port=srv.port,
|
|
|
|
|
)
|
feat: add Admin Panel with JWT auth, DB settings, and integration management
Complete admin backend with login, where all integrations (weather, news,
Home Assistant, Vikunja, Unraid, MQTT) can be configured via web UI instead
of ENV variables. Two-layer config: ENV seeds DB on first start, then DB
is source of truth. Auto-migration system on startup.
Backend: db.py shared pool, auth.py JWT, settings_service CRUD, seed_service,
admin router (protected), test_connections per integration, config.py rewrite.
Frontend: react-router v6, login page, admin layout with sidebar, 8 settings
pages (General, Weather, News, HA, Vikunja, Unraid, MQTT, ChangePassword),
shared IntegrationForm + TestButton components.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 10:37:30 +01:00
|
|
|
for srv in get_settings().unraid_servers
|
2026-03-02 01:48:51 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
servers_data: List[Dict[str, Any]] = []
|
|
|
|
|
try:
|
|
|
|
|
servers_data = await fetch_all_servers(server_configs)
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logger.exception("Failed to fetch Unraid server data")
|
|
|
|
|
return {
|
|
|
|
|
"servers": [],
|
|
|
|
|
"error": True,
|
|
|
|
|
"message": str(exc),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
payload: Dict[str, Any] = {
|
|
|
|
|
"servers": servers_data,
|
|
|
|
|
}
|
|
|
|
|
|
feat: add Admin Panel with JWT auth, DB settings, and integration management
Complete admin backend with login, where all integrations (weather, news,
Home Assistant, Vikunja, Unraid, MQTT) can be configured via web UI instead
of ENV variables. Two-layer config: ENV seeds DB on first start, then DB
is source of truth. Auto-migration system on startup.
Backend: db.py shared pool, auth.py JWT, settings_service CRUD, seed_service,
admin router (protected), test_connections per integration, config.py rewrite.
Frontend: react-router v6, login page, admin layout with sidebar, 8 settings
pages (General, Weather, News, HA, Vikunja, Unraid, MQTT, ChangePassword),
shared IntegrationForm + TestButton components.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 10:37:30 +01:00
|
|
|
await cache.set(CACHE_KEY, payload, get_settings().unraid_cache_ttl)
|
2026-03-02 01:48:51 +01:00
|
|
|
return payload
|