feat(ui): alerts, monitors, hosts, schedules and maintenance lists put problems first, with since-times (#5210)
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 1m8s
CI / unit (push) Successful in 1m25s
CI / publish (push) Successful in 1m17s

#5210 "Problems first, with since-time, across every list" (milestone 477),
first batch.

- Alerts: the Active list reads firing, no data, acknowledged, pending, the
  longest-running first, and re-polls itself. An acknowledged alert says how
  long it has been breaching (from the alert's events; acknowledging moves
  last_transition_at) and, apart from that, who acknowledged it and when.
  Rules show what each is doing now; disabled rules sort last. The current
  value reads the latest-value table (#5208) instead of plugin_metrics.
- Monitors: a down monitor says "Down 12m · connection refused" in the list.
- Hosts: sorted down, agent gone quiet, pending, healthy. The agent column
  shows "—" for a missing reading (was 0%) and a Stale badge with its age.
  agent_metrics_by_host is gone; the list reads agent_overview_by_host.
- Schedules: failing first (failed or interrupted run, or a firing that could
  not start one), then running, then the rest, paused last; status badge
  from the shared states.
- Maintenance windows: active (ending soonest), then upcoming (starting
  soonest), with expired folded away; each says when it ends/starts/ended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 23:58:56 -04:00
co-authored by Claude Opus 5.5
parent a39633626b
commit 5a14e7c693
16 changed files with 335 additions and 103 deletions
+5 -2
View File
@@ -50,14 +50,17 @@ async def list_hosts():
hosts = result.scalars().all()
host_status = await host_svc.host_status(db, [h.id for h in hosts])
uptime = await host_svc.compute_uptime(db)
agent_metrics = await host_svc.agent_metrics_by_host(db, [h.name for h in hosts])
agent = await host_svc.agent_overview_by_host(
db, [h.name for h in hosts], host_svc.agent_stale_after_seconds(current_app.config))
hosts = sorted(hosts, key=lambda h: (
host_svc.host_rank(host_status.get(h.id), agent.get(h.name)), h.name.lower()))
return await render_template(
"hosts/list.html",
hosts=hosts,
host_status=host_status,
uptime=uptime,
agent_metrics=agent_metrics,
agent=agent,
)
+15 -11
View File
@@ -113,6 +113,21 @@ async def host_status(db, host_ids: list[str]) -> dict[str, dict]:
return out
def host_rank(status: dict | None, agent: dict | None) -> int:
"""Where a host sorts in the Hosts list: a down monitor first, then an
agent gone quiet, then monitors not yet checked, then the healthy; a host
with neither monitors nor agent last."""
if status and status["state"] == "down":
return 0
if agent and not agent.get("fresh"):
return 1
if status and status["state"] == "pending":
return 2
if status or agent:
return 3
return 4
async def host_monitors(db, host_id: str) -> list[dict]:
"""Display rows for the monitors linked to one host (host hub section)."""
monitors = (await db.execute(
@@ -134,17 +149,6 @@ async def host_monitors(db, host_id: str) -> list[dict]:
return data
async def agent_metrics_by_host(db, host_names: list[str]) -> dict[str, dict]:
"""Latest agent cpu/mem per host name, from plugin_metric_latest.
Core-safe (no host_agent import), so the Hosts list can show an
at-a-glance agent column without importing the host_agent plugin.
"""
from steward.core.metric_series import latest_by_resource
latest = await latest_by_resource(db, "host_agent", host_names, ("cpu_pct", "mem_used_pct"))
return {name: {m: r.value for m, r in metrics.items()} for name, metrics in latest.items()}
async def agent_overview_by_host(
db, host_names: list[str], stale_after_seconds: int = 180,
) -> dict[str, dict]: