Files
FabledSteward/steward/status/routes.py
T
bvandeusenandClaude Opus 5.5 434127b3e1
CI / lint (push) Successful in 4s
CI / integration (push) Successful in 1m10s
CI / unit (push) Successful in 1m36s
CI / publish (push) Successful in 1m28s
feat(monitors): Monitors absorbs the Status page; Status is removed (#5270)
Status repeated the Monitors page's counts, check strip and uptime. Monitors
now has one header row and every column Status had: the last 30 checks,
latest response with its trend, uptime over 24h / 7d / 30d (the range picker
goes) and TLS days on every row. /status and /status/rows and the nav link
are removed outright; the dashboard Overview (/status/widget) stays and its
Details link goes to Monitors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:36:38 -04:00

51 lines
2.0 KiB
Python

from __future__ import annotations
from quart import Blueprint, current_app, render_template, request
from sqlalchemy import func, select
from steward.alerts.service import active_alerts, alert_label
from steward.auth.middleware import require_role
from steward.core.status import collect_status
from steward.models.hosts import Host
from steward.models.users import UserRole
status_bp = Blueprint("status", __name__, url_prefix="/status")
def _summarize(entries) -> tuple[int, int, int]:
up = sum(1 for e in entries if e.status == "up")
down = sum(1 for e in entries if e.status == "down")
pending = sum(1 for e in entries if e.status == "pending")
return up, down, pending
@status_bp.get("/widget")
@require_role(UserRole.viewer)
async def widget():
"""HTMX dashboard 'Overview' widget — the single at-a-glance summary that
replaced the old fixed top strip: host count + monitor up/down/pending +
problem list + an alerts link."""
async with current_app.db_sessionmaker() as db:
entries = await collect_status(db)
total_hosts = (await db.execute(
select(func.count()).select_from(Host))).scalar()
alerts = await active_alerts(db)
up, down, pending = _summarize(entries)
return await render_template(
"status/widget.html",
entries=entries, up=up, down=down, pending=pending,
total_hosts=total_hosts, alerts=overview_alerts(alerts),
widget_id=request.args.get("wid", "0"),
)
def overview_alerts(alerts) -> list[dict]:
"""The Overview's alert lines: breaching or silent first, then those
someone has taken; each {rule, label, since}."""
order = {"firing": 0, "no_data": 1, "pending": 2, "acknowledged": 3}
rows = []
for state, rule in alerts:
label = alert_label(state)
since = state.no_data_since if label == "no_data" else state.last_transition_at
rows.append({"rule": rule, "label": label, "since": since})
return sorted(rows, key=lambda r: order.get(r["label"], 9))