Files
Homelab-manager/web/src/components/StatusStrip.tsx
T
bobbanandClaude Sonnet 5.5 171511c6db Fold alerts under their host, recurring maintenance, run playbooks from alerts, and an Updates page
- Servers can say what they run on (or it is worked out from the Proxmox node); when the host is
  down the guests' offline alerts fold under it: held back, not counted, not notified, still recorded.
- Recurring maintenance schedules made into ordinary windows a week ahead (maintenance_schedules).
- Run a Semaphore template limited to a server from its page or an alert, and watch the run.
- Agents report pending updates (apt, dnf, zypper, Windows Update); an Updates page lists them.
- Migrations 0024 and 0025.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-17 01:35:15 +02:00

101 lines
4.2 KiB
TypeScript

import { Link } from "react-router-dom";
import { IconAlertTriangle, IconCircleCheck, IconInfoCircle } from "@tabler/icons-react";
import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport";
const SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 } as const;
/** One line at the top of the dashboard: is anything wrong right now? Reads the same alert report as the Alerts page. */
export default function StatusStrip() {
const { report, failed, reload } = useAlertsReport();
if (!report) {
return (
<div className="alert alert-secondary d-flex align-items-center gap-2 mb-3" role="status">
<IconInfoCircle size={18} />
<div>{failed ? "Couldn't load the alert status." : "Checking status…"}</div>
{failed && (
<button type="button" className="btn btn-sm ms-auto" onClick={reload}>
Try again
</button>
)}
</div>
);
}
const badge = alertBadge(report);
const active = report.alerts
.filter((a) => !a.silenced && a.severity !== "info")
.sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
const silenced = report.counts.silenced;
const grouped = report.counts.grouped ?? 0;
const blind = report.couldntCheck.length;
const notes: string[] = [];
if (silenced > 0) notes.push(`${silenced} silenced by maintenance`);
if (grouped > 0) notes.push(`${grouped} more explained by a server that is down`);
if (blind > 0 && badge) notes.push(`${blind} check${blind === 1 ? "" : "s"} couldn't run`);
if (!badge) {
// Nothing is wrong that we can see — but if some checks couldn't run, "all clear" would claim more than is known.
const unsure = blind > 0;
return (
<div className={`alert ${unsure ? "alert-warning" : "alert-success"} mb-3`} role="status">
<div className="d-flex align-items-center gap-2">
{unsure ? <IconAlertTriangle size={18} className="flex-shrink-0" /> : <IconCircleCheck size={18} className="flex-shrink-0" />}
<div>
<strong>{unsure ? "No active alerts, but some checks couldn't run." : "All clear."}</strong>{" "}
{unsure ? (
<span>
{report.couldntCheck.map((c) => c.name).join(", ")} — see <Link to="/alerts">Alerts</Link> for what that leaves unchecked.
</span>
) : (
<span className="text-secondary">No active alerts.</span>
)}
{silenced > 0 && <span className="text-secondary"> {silenced} silenced by maintenance.</span>}
{grouped > 0 && <span className="text-secondary"> {grouped} more explained by a server that is down.</span>}
</div>
</div>
</div>
);
}
const parts = [
report.counts.critical > 0 ? `${report.counts.critical} critical` : null,
report.counts.warning > 0 ? `${report.counts.warning} warning${report.counts.warning === 1 ? "" : "s"}` : null,
].filter(Boolean);
return (
<div className={`alert ${badge.level === "critical" ? "alert-danger" : "alert-warning"} mb-3`} role="alert">
<div className="d-flex gap-2 w-100">
<IconAlertTriangle size={18} className="flex-shrink-0 mt-1" />
<div className="flex-fill">
<div className="d-flex flex-wrap align-items-center gap-2">
<div>
<strong>
{badge.count} {badge.count === 1 ? "thing needs" : "things need"} attention
</strong>{" "}
— {parts.join(", ")}
{notes.length > 0 && <span className="opacity-75"> · {notes.join(" · ")}</span>}
</div>
<Link to="/alerts" className="btn btn-sm ms-auto flex-shrink-0">
View all alerts
</Link>
</div>
{active.length > 0 && (
<ul className="mb-0 mt-2 ps-3">
{active.slice(0, 3).map((a) => (
<li key={a.id}>
<Link to={a.link ?? "/alerts"} className="alert-link">
{a.message}
</Link>
</li>
))}
{active.length > 3 && <li className="opacity-75">and {active.length - 3} more</li>}
</ul>
)}
</div>
</div>
</div>
);
}