Dependency map, impact preview in maintenance, and a calmer Alerts page
- Map: a Dependencies view showing what would go down with a picked box and what it relies on - Maintenance: lists what depends on a target and can silence those too (same time, audited); the recurring form and update drawer show the same note - Alerts: a headline on where things stand, held-back alerts nested under their cause, severity edge on rows; caused-by now carries the explaining alert's id Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec9c2f73f0
commit
9caa414829
19 files changed
+944
-40
No files matched your search
+120
-8
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Fragment, useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type AlertCategory, type AlertItem, type AlertSeverity, type AlertsReport, type CurrentUser } from "../api/client";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
@@ -52,6 +52,23 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
// Which alerts to show by whether somebody is on them, and the one whose acknowledgement is being edited.
|
||||
const [attention, setAttention] = useState<"all" | "unacknowledged" | "acknowledged" | "mine">("all");
|
||||
const [acking, setAcking] = useState<AlertItem | null>(null);
|
||||
// Held-back alerts are nested under the one that explains them (on by default; remembered), and each parent opens to show them.
|
||||
const [grouped, setGrouped] = useState(() => {
|
||||
try {
|
||||
return localStorage.getItem("alerts.grouped") !== "0";
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
const [open, setOpen] = useState<Set<string>>(new Set());
|
||||
function chooseGrouped(on: boolean) {
|
||||
setGrouped(on);
|
||||
try {
|
||||
localStorage.setItem("alerts.grouped", on ? "1" : "0");
|
||||
} catch {
|
||||
// a remembered choice is only a convenience
|
||||
}
|
||||
}
|
||||
|
||||
function load(refresh = false) {
|
||||
setLoading(true);
|
||||
@@ -69,18 +86,47 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
void load();
|
||||
}, []);
|
||||
|
||||
const rows: Row[] = useMemo(() => {
|
||||
if (!report) return [];
|
||||
const { rows, childrenOf } = useMemo(() => {
|
||||
const none = new Map<string, Row[]>();
|
||||
if (!report) return { rows: [] as Row[], childrenOf: none };
|
||||
const q = search.trim().toLowerCase();
|
||||
return report.alerts
|
||||
.filter((a) => (severity === "all" || a.severity === severity) && (category === "all" || a.category === category) && (showSilenced || !a.silenced))
|
||||
const base: Row[] = report.alerts
|
||||
.filter((a) => (severity === "all" || a.severity === severity) && (category === "all" || a.category === category))
|
||||
.filter((a) => {
|
||||
const on = !!a.ack?.active;
|
||||
return attention === "all" || (attention === "unacknowledged" ? !on : attention === "acknowledged" ? on : on && a.ack?.assignee?.id === user.id);
|
||||
})
|
||||
.filter((a) => !q || [a.message, a.source, CATEGORY_LABELS[a.category]].some((v) => v.toLowerCase().includes(q)))
|
||||
.map((a) => ({ ...a, rank: SEVERITY[a.severity].rank }));
|
||||
}, [report, severity, category, search, showSilenced, attention, user.id]);
|
||||
// An alert held back by another is nested under it when that one is on the list too; otherwise it stands on its own.
|
||||
const ids = new Set(base.map((a) => a.id));
|
||||
const children = new Map<string, Row[]>();
|
||||
const nested = new Set<string>();
|
||||
if (grouped) {
|
||||
for (const a of base) {
|
||||
const parent = a.causedBy?.alertId;
|
||||
if (parent && parent !== a.id && ids.has(parent)) {
|
||||
children.set(parent, [...(children.get(parent) ?? []), a]);
|
||||
nested.add(a.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { rows: base.filter((a) => !nested.has(a.id) && (showSilenced || !a.silenced)), childrenOf: children };
|
||||
}, [report, severity, category, search, showSilenced, attention, user.id, grouped]);
|
||||
|
||||
// One line on where things stand: how many need someone, and which problems explain the rest.
|
||||
const headline = useMemo(() => {
|
||||
if (!report || report.alerts.length === 0) return null;
|
||||
const standing = report.alerts.filter((a) => !a.silenced);
|
||||
const acknowledged = standing.filter((a) => a.ack?.active).length;
|
||||
const held = report.alerts.filter((a) => a.causedBy).length;
|
||||
const roots = standing
|
||||
.filter((a) => (a.affects?.length ?? 0) > 0)
|
||||
.map((a) => ({ name: a.target?.name ?? a.source, count: report.alerts.filter((x) => x.causedBy?.alertId === a.id).length }))
|
||||
.filter((r) => r.count > 0);
|
||||
const critical = standing.some((a) => a.severity === "critical");
|
||||
return { standing: standing.length, acknowledged, held, roots, tone: standing.length === 0 ? "green" : critical ? "red" : "yellow" };
|
||||
}, [report]);
|
||||
|
||||
// No initial sort: the server already puts active problems first, worst first.
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(rows);
|
||||
@@ -143,6 +189,33 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
|
||||
{report && (
|
||||
<>
|
||||
{headline && (
|
||||
<div className={`card mb-3 alerts-headline alerts-headline-${headline.tone}`} role="status">
|
||||
<div className="card-body py-3">
|
||||
<div className="h3 mb-1">
|
||||
{headline.standing === 0 ? "Nothing needs attention" : `${headline.standing} ${headline.standing === 1 ? "problem needs" : "problems need"} attention`}
|
||||
{headline.acknowledged > 0 && headline.standing > 0 && <span className="text-secondary fw-normal fs-4"> · {headline.acknowledged} acknowledged</span>}
|
||||
</div>
|
||||
{headline.held > 0 && (
|
||||
<div className="text-secondary">
|
||||
{headline.held} more {headline.held === 1 ? "is" : "are"} held back because something they depend on is down
|
||||
{headline.roots.length > 0 && (
|
||||
<>
|
||||
{" "}
|
||||
— {headline.roots.map((r, i) => (
|
||||
<span key={r.name}>
|
||||
{i > 0 && ", "}
|
||||
<strong>{r.name}</strong> accounts for {r.count}
|
||||
</span>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="row g-3 mb-3">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-md-3" key={c.label}>
|
||||
@@ -220,6 +293,12 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
<option value="mine">Handed to me</option>
|
||||
</select>
|
||||
)}
|
||||
{(counts?.grouped ?? 0) > 0 && (
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={grouped} onChange={(e) => chooseGrouped(e.target.checked)} />
|
||||
<span className="form-check-label">Group under their cause</span>
|
||||
</label>
|
||||
)}
|
||||
{(counts?.silenced ?? 0) + (counts?.grouped ?? 0) > 0 && (
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={showSilenced} onChange={(e) => setShowSilenced(e.target.checked)} />
|
||||
@@ -246,7 +325,8 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</thead>
|
||||
<tbody>
|
||||
{(pageItems ?? []).map((a) => (
|
||||
<tr key={a.id} className={a.silenced ? "text-secondary" : undefined} style={a.silenced ? { opacity: 0.65 } : undefined}>
|
||||
<Fragment key={a.id}>
|
||||
<tr className={`alert-row alert-row-${a.severity}${a.silenced ? " text-secondary" : ""}`} style={a.silenced ? { opacity: 0.65 } : undefined}>
|
||||
<td>
|
||||
<span className={`badge ${SEVERITY[a.severity].badge}`}>{SEVERITY[a.severity].label}</span>
|
||||
</td>
|
||||
@@ -288,9 +368,26 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
{a.affects && a.affects.length > 0 && (
|
||||
<div className="text-secondary small">
|
||||
Also takes down {a.affects.length} {a.affects.length === 1 ? "server" : "servers"}: {a.affects.join(", ")}
|
||||
Also takes down {a.affects.length} {a.affects.length === 1 ? "thing" : "things"}: {a.affects.join(", ")}
|
||||
</div>
|
||||
)}
|
||||
{(childrenOf.get(a.id)?.length ?? 0) > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-link btn-sm p-0 mt-1"
|
||||
aria-expanded={open.has(a.id)}
|
||||
onClick={() =>
|
||||
setOpen((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(a.id)) next.delete(a.id);
|
||||
else next.add(a.id);
|
||||
return next;
|
||||
})
|
||||
}
|
||||
>
|
||||
{open.has(a.id) ? "Hide" : "Show"} the {childrenOf.get(a.id)!.length} {childrenOf.get(a.id)!.length === 1 ? "alert" : "alerts"} held back under this
|
||||
</button>
|
||||
)}
|
||||
{a.ticket &&
|
||||
(() => {
|
||||
const label = a.ticket.number ? `Ticket #${a.ticket.number}` : "Ticket opened";
|
||||
@@ -320,6 +417,21 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
{open.has(a.id) &&
|
||||
(childrenOf.get(a.id) ?? []).map((c) => (
|
||||
<tr key={c.id} className="alert-row alert-row-child text-secondary">
|
||||
<td>
|
||||
<span className={`badge ${SEVERITY[c.severity].badge}`}>{SEVERITY[c.severity].label}</span>
|
||||
</td>
|
||||
<td>{CATEGORY_LABELS[c.category]}</td>
|
||||
<td>{c.link ? <Link to={c.link}>{c.source}</Link> : c.source}</td>
|
||||
<td colSpan={canSilence ? 2 : 1}>
|
||||
<span aria-hidden="true">↳ </span>
|
||||
{c.message}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</Fragment>
|
||||
))}
|
||||
{(sorted ?? []).length === 0 && (
|
||||
<tr>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import ImpactNote from "../components/ImpactNote";
|
||||
import {
|
||||
api,
|
||||
type CurrentUser,
|
||||
@@ -46,6 +47,8 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
const [aliasBusy, setAliasBusy] = useState(false);
|
||||
const [aliasError, setAliasError] = useState<string | null>(null);
|
||||
const [targets, setTargets] = useState<MaintenanceTargets | null>(null);
|
||||
// Whether what depends on the chosen target is silenced along with it (offered once the target is known to have dependents).
|
||||
const [withDependents, setWithDependents] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
|
||||
@@ -144,15 +147,17 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
setError(null);
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.maintenance.start({
|
||||
const res = await api.maintenance.start({
|
||||
targetType: targetType as MaintenanceTargetType,
|
||||
targetId: Number(id),
|
||||
minutes,
|
||||
reason: reason.trim() || undefined,
|
||||
withDependents: withDependents || undefined,
|
||||
});
|
||||
setTarget("");
|
||||
setReason("");
|
||||
toast.success("Maintenance started. Alerts for it are silenced until it ends.");
|
||||
const also = res.alsoSilenced?.length ?? 0;
|
||||
toast.success(also > 0 ? `Maintenance started, and on ${also} thing${also === 1 ? "" : "s"} that depend on it. Alerts for them are silenced until it ends.` : "Maintenance started. Alerts for it are silenced until it ends.");
|
||||
load();
|
||||
announceChange();
|
||||
} catch (err) {
|
||||
@@ -316,6 +321,11 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{(target.startsWith("server:") || target.startsWith("integration:")) && (
|
||||
<div className="col-12">
|
||||
<ImpactNote targets={[{ type: target.split(":")[0], id: Number(target.split(":")[1]) }]} silence={{ value: withDependents, onChange: setWithDependents }} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="card-footer">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !target}>
|
||||
|
||||
+54
-12
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import DependencyMap from "../components/DependencyMap";
|
||||
import { api, type MapData, type MapNode } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { PageSkeleton } from "../components/Skeleton";
|
||||
@@ -75,6 +76,48 @@ function layout(data: MapData): { placed: Map<string, Placed>; width: number; he
|
||||
|
||||
/** The picture: how the servers, their Proxmox hosts, DNS names and monitors connect. Hover or tab to a box to light up its connections. */
|
||||
export default function MapPage() {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const view = params.get("view") === "dependencies" ? "dependencies" : "connections";
|
||||
const choose = (v: "connections" | "dependencies") =>
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (v === "connections") next.delete("view");
|
||||
else next.set("view", v);
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<h2 className="page-title mb-0">Map</h2>
|
||||
<div className="btn-group ms-auto" role="group" aria-label="What to draw">
|
||||
<button type="button" className={`btn btn-sm ${view === "connections" ? "active" : ""}`} aria-pressed={view === "connections"} onClick={() => choose("connections")}>
|
||||
Connections
|
||||
</button>
|
||||
<button type="button" className={`btn btn-sm ${view === "dependencies" ? "active" : ""}`} aria-pressed={view === "dependencies"} onClick={() => choose("dependencies")}>
|
||||
Dependencies
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{view === "connections" ? (
|
||||
<ConnectionsMap />
|
||||
) : (
|
||||
<>
|
||||
<p className="text-secondary">
|
||||
What needs what: a server that runs on another, a service that needs the server it is installed on. Pick a box to see what would go down with it before you reboot it.{" "}
|
||||
<Link to="/dependencies">Edit dependencies</Link>
|
||||
</p>
|
||||
<DependencyMap />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ConnectionsMap() {
|
||||
const [data, setData] = useState<MapData | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [focus, setFocus] = useState<string | null>(null);
|
||||
@@ -86,7 +129,7 @@ export default function MapPage() {
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}, []);
|
||||
|
||||
const view = useMemo(() => (data ? layout(data) : null), [data]);
|
||||
const drawing = useMemo(() => (data ? layout(data) : null), [data]);
|
||||
const lit = useMemo(() => {
|
||||
if (!data || !focus) return null;
|
||||
const set = new Set<string>([focus]);
|
||||
@@ -99,7 +142,6 @@ export default function MapPage() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<h2 className="page-title mb-1">Map</h2>
|
||||
<p className="text-secondary">
|
||||
How things connect: which Proxmox host a server runs on, which DNS names point at it, and which Uptime Kuma monitors watch it. Hover or tab to a box to light up what it is
|
||||
connected to.
|
||||
@@ -111,22 +153,22 @@ export default function MapPage() {
|
||||
</div>
|
||||
))}
|
||||
{!data && !error && <PageSkeleton />}
|
||||
{data && view && data.nodes.length === 0 && <div className="card"><div className="card-body text-secondary">Nothing to draw yet — add a server first.</div></div>}
|
||||
{data && view && data.nodes.length > 0 && (
|
||||
{data && drawing && data.nodes.length === 0 && <div className="card"><div className="card-body text-secondary">Nothing to draw yet — add a server first.</div></div>}
|
||||
{data && drawing && data.nodes.length > 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body map-scroll">
|
||||
<div className="map-columns" style={{ width: view.width }}>
|
||||
{view.columns.map((c) => (
|
||||
<div className="map-columns" style={{ width: drawing.width }}>
|
||||
{drawing.columns.map((c) => (
|
||||
<div key={c.title} className="map-column-title" style={{ left: c.x, width: NODE_W }}>
|
||||
{c.title}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="map-canvas" style={{ width: view.width, height: view.height }}>
|
||||
<svg className="map-lines" width={view.width} height={view.height} aria-hidden="true">
|
||||
<div className="map-canvas" style={{ width: drawing.width, height: drawing.height }}>
|
||||
<svg className="map-lines" width={drawing.width} height={drawing.height} aria-hidden="true">
|
||||
{data.edges.map((e) => {
|
||||
const a = view.placed.get(e.from);
|
||||
const b = view.placed.get(e.to);
|
||||
const a = drawing.placed.get(e.from);
|
||||
const b = drawing.placed.get(e.to);
|
||||
if (!a || !b) return null;
|
||||
// Always drawn from the node on the left to the one on the right.
|
||||
const [l, r] = a.x <= b.x ? [a, b] : [b, a];
|
||||
@@ -139,7 +181,7 @@ export default function MapPage() {
|
||||
return <path key={`${e.from}>${e.to}`} d={`M${x1},${y1} C${mid},${y1} ${mid},${y2} ${x2},${y2}`} className={active ? "map-edge" : "map-edge map-dim"} fill="none" />;
|
||||
})}
|
||||
</svg>
|
||||
{[...view.placed.values()].map((n) => {
|
||||
{[...drawing.placed.values()].map((n) => {
|
||||
const dim = lit && !lit.has(n.id);
|
||||
const body = (
|
||||
<>
|
||||
|
||||
Reference in new issue
Block a user