fix w statusie watchdog-mux

This commit is contained in:
Mateusz Gruszczyński
2025-10-17 13:59:45 +02:00
parent 5f0cc07c46
commit 9a21739eb9

28
app.py
View File

@@ -300,16 +300,22 @@ def units_for_node(node: str) -> Dict[str, str]:
states: Dict[str, str] = {} states: Dict[str, str] = {}
def norm_state(s: dict) -> str: def norm_state(s: dict) -> str:
# Proxmox bywa: {"state":"enabled","active":"active"} albo {"active":1} albo {"status":"running"} itp. raw_active = str(
raw_active = str(s.get("active", "")).lower() s.get("active", "") or
status = str(s.get("status", "")).lower() s.get("active-state", "") or
substate = str(s.get("substate", "")).lower() s.get("ActiveState", "") or
state = str(s.get("state", "")).lower() s.get("activestate", "")
).lower()
status = str(s.get("status", "")).lower()
substate = str(s.get("substate", "")).lower()
state = str(s.get("state", "")).lower()
any_active = ( any_active = (
raw_active in ("active", "running", "1", "true") or raw_active in ("active", "running", "1", "true") or
status in ("active", "running") or status in ("active", "running") or
substate in ("running") or substate in ("running", "active") or
("running" in state) ("running" in state or "active" in state)
) )
return "active" if any_active else "inactive" return "active" if any_active else "inactive"
@@ -319,12 +325,10 @@ def units_for_node(node: str) -> Dict[str, str]:
if name in wanted: if name in wanted:
states[name] = norm_state(s) states[name] = norm_state(s)
# fallback lokalny tylko jeśli API nic nie zwróciło for u in wanted:
if not states: if states.get(u) != "active" and is_active(u):
for u in wanted: states[u] = "active"
states[u] = "active" if is_active(u) else "inactive"
# zawsze zwróć pełny zestaw
for u in wanted: for u in wanted:
states.setdefault(u, "inactive") states.setdefault(u, "inactive")