diff --git a/steward/core/widgets.py b/steward/core/widgets.py index 401db37..2f9be05 100644 --- a/steward/core/widgets.py +++ b/steward/core/widgets.py @@ -24,8 +24,8 @@ WIDGET_REGISTRY: dict[str, dict] = { }, "status_overview": { "key": "status_overview", - "label": "Status — Overview", - "description": "Unified up/down/pending summary across ping, DNS, and HTTP monitors", + "label": "Overview", + "description": "At-a-glance summary — host count, monitor up/down/pending, and alerts", "hx_url": "/status/widget", "detail_url": "/status/", "plugin": None, diff --git a/steward/dashboard/routes.py b/steward/dashboard/routes.py index ddf32a3..5ce2a73 100644 --- a/steward/dashboard/routes.py +++ b/steward/dashboard/routes.py @@ -9,7 +9,6 @@ from sqlalchemy import select, func, update from steward.auth.middleware import require_role, current_user_id from steward.models.users import UserRole from steward.models.hosts import Host -from steward.models.monitors import PingResult, DnsResult from steward.models.dashboard import Dashboard, DashboardWidget, DashboardShareToken from steward.core.settings import public_base_url from steward.core.widgets import get_available_widgets, WIDGET_REGISTRY @@ -103,42 +102,6 @@ async def _get_or_create_system_default(db) -> Dashboard: return dash -async def _get_summary_stats(db) -> dict: - latest_ping_subq = ( - select(PingResult.host_id, func.max(PingResult.probed_at).label("max_at")) - .group_by(PingResult.host_id).subquery() - ) - pr = await db.execute( - select(PingResult).join( - latest_ping_subq, - (PingResult.host_id == latest_ping_subq.c.host_id) - & (PingResult.probed_at == latest_ping_subq.c.max_at), - ) - ) - pings = list(pr.scalars()) - ping_up = sum(1 for p in pings if p.status.value == "up") - ping_down = sum(1 for p in pings if p.status.value == "down") - - latest_dns_subq = ( - select(DnsResult.host_id, func.max(DnsResult.resolved_at).label("max_at")) - .group_by(DnsResult.host_id).subquery() - ) - dr = await db.execute( - select(DnsResult).join( - latest_dns_subq, - (DnsResult.host_id == latest_dns_subq.c.host_id) - & (DnsResult.resolved_at == latest_dns_subq.c.max_at), - ) - ) - dns = list(dr.scalars()) - dns_ok = sum(1 for d in dns if d.status.value == "resolved") - dns_fail = sum(1 for d in dns if d.status.value != "resolved") - total = (await db.execute(select(func.count()).select_from(Host))).scalar() - - return dict(ping_up=ping_up, ping_down=ping_down, - dns_ok=dns_ok, dns_fail=dns_fail, total_hosts=total) - - def _resolve_widgets(widgets: list[DashboardWidget]) -> list[dict]: plugins_cfg = current_app.config.get("PLUGINS", {}) out = [] @@ -199,7 +162,6 @@ async def view(dash_id: int): if dash is None or not _can_view(dash, user_id, user_role): abort(404) - stats = await _get_summary_stats(db) widgets = await _get_widgets(db, dash_id) accessible = await _accessible_dashboards(db, user_id, user_role) can_edit = _can_edit(dash, user_id, user_role) @@ -224,7 +186,6 @@ async def view(dash_id: int): can_edit=can_edit, addable=addable, hosts=hosts, - **stats, ) diff --git a/steward/status/routes.py b/steward/status/routes.py index d4edcc9..202c33b 100644 --- a/steward/status/routes.py +++ b/steward/status/routes.py @@ -1,8 +1,10 @@ from __future__ import annotations from quart import Blueprint, current_app, render_template, request +from sqlalchemy import func, select from steward.auth.middleware import require_role from steward.core.status import collect_status, sparkline_svg +from steward.models.hosts import Host from steward.models.users import UserRole status_bp = Blueprint("status", __name__, url_prefix="/status") @@ -40,12 +42,17 @@ async def rows(): @status_bp.get("/widget") @require_role(UserRole.viewer) async def widget(): - """HTMX dashboard widget — compact up/down/pending summary + problem list.""" + """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() up, down, pending = _summarize(entries) return await render_template( "status/widget.html", entries=entries, up=up, down=down, pending=pending, + total_hosts=total_hosts, widget_id=request.args.get("wid", "0"), ) diff --git a/steward/templates/dashboard/index.html b/steward/templates/dashboard/index.html index 6feadac..07ebd16 100644 --- a/steward/templates/dashboard/index.html +++ b/steward/templates/dashboard/index.html @@ -33,37 +33,8 @@ -{# ── Summary strip ─────────────────────────────────────────────────────────── #} -