Flapping alerts, a noise report and bulk actions with undo

Flapping: an alert raised three times within an hour is announced once as
flapping, its further raise/clear messages are held until it has been calm
for an hour, and one message then says whether it is still active. Event
webhooks still hear everything. The state survives restarts.

Alerts > Noise lists the alerts that keep coming back (7-180 days): how often,
how long, most in an hour, and a hint on what helps.

Bulk actions on Alerts (acknowledge, remove acknowledgement, silence), Servers
(tag, silence, runs on) and Inventory (location and dates, print labels). Each
reports what it left alone and why, and has an Undo on the toast.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-19 23:55:09 +02:00
1 parent be6c5552bd
commit 73a06ebe63
35 files changed
+2546 -17

No files matched your search

+99 -5
View File
@@ -20,6 +20,10 @@ import { summariseAlerts } from "../utils/alertSummary";
import { EmptyRow } from "../components/EmptyState";
import IncidentHistory, { incidentPath } from "../components/IncidentHistory";
import ViewTabs from "../components/ViewTabs";
import AlertNoise from "../components/AlertNoise";
import BulkBar from "../components/BulkBar";
import { AckBulkDrawer, SilenceBulkDrawer } from "../components/BulkDrawers";
import { doBulk, plural } from "../utils/bulk";
const SEVERITY: Record<AlertSeverity, { label: string; badge: string; rank: number }> = {
critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 },
@@ -42,27 +46,29 @@ const CATEGORY_LABELS: Record<AlertCategory, string> = {
type Row = AlertItem & { rank: number };
/** Now and History: what is wrong right now, and every time something was raised and went away. The same page, switched by `?view=history`. */
const alertTabs = (view: "now" | "history") => (
/** Now, History and Noise: what is wrong right now, every time something was raised and went away, and which alerts keep coming back. The same page, switched by `?view=`. */
const alertTabs = (view: "now" | "history" | "noise") => (
<ViewTabs
label="Alerts view"
tabs={[
{ to: "/alerts", label: "Now", active: view === "now" },
{ to: "/alerts?view=history", label: "History", active: view === "history" },
{ to: "/alerts?view=noise", label: "Noise", active: view === "noise" },
]}
/>
);
export default function Alerts({ user }: { user: CurrentUser }) {
const [params] = useSearchParams();
if (params.get("view") === "history") {
const view = params.get("view");
if (view === "history" || view === "noise") {
return (
<>
<div className="d-flex align-items-center mb-2">
<h2 className="page-title mb-0">Alerts</h2>
</div>
{alertTabs("history")}
<IncidentHistory />
{alertTabs(view)}
{view === "history" ? <IncidentHistory /> : <AlertNoise />}
</>
);
}
@@ -88,6 +94,9 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
// 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);
// Alerts ticked for a bulk action, and which bulk form is open.
const [picked, setPicked] = useState<Set<string>>(new Set());
const [bulkForm, setBulkForm] = useState<"ack" | "silence" | 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 {
@@ -167,6 +176,44 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
);
}
// Only alerts that are still there can be picked (one that cleared since the last look just drops out).
const pickedIds = useMemo(() => {
const here = new Set((report?.alerts ?? []).map((a) => a.id));
return [...picked].filter((id) => here.has(id));
}, [picked, report]);
const shownIds = useMemo(() => (sorted ?? []).filter((a) => !a.silenced).map((a) => a.id), [sorted]);
const allShownPicked = shownIds.length > 0 && shownIds.every((id) => picked.has(id));
function togglePicked(id: string) {
setPicked((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
function afterBulk() {
void load(true);
reloadBadge();
}
async function bulkAck(v: { note: string; assigneeId: number | null; hours: number | null }) {
const ok = await doBulk({ call: api.bulk.alerts, body: { action: "acknowledge", alertIds: pickedIds, ...v }, done: (r) => `${plural(r.changed, "alert")} acknowledged.`, reload: afterBulk });
if (ok) {
setBulkForm(null);
setPicked(new Set());
}
}
async function bulkUnack() {
const ok = await doBulk({ call: api.bulk.alerts, body: { action: "unacknowledge", alertIds: pickedIds }, done: (r) => `${plural(r.changed, "acknowledgement")} removed.`, reload: afterBulk });
if (ok) setPicked(new Set());
}
async function bulkSilence(v: { minutes: number; reason: string }) {
const ok = await doBulk({ call: api.bulk.alerts, body: { action: "silence", alertIds: pickedIds, minutes: v.minutes, reason: v.reason }, done: (r) => `${plural(r.changed, "thing")} put under maintenance.`, reload: afterBulk });
if (ok) {
setBulkForm(null);
setPicked(new Set());
}
}
const counts = report?.counts;
const nothingFound = report !== null && report.alerts.length === 0;
const cards: { label: string; value: number | undefined; color: string }[] = [
@@ -321,6 +368,26 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
<option value="mine">Handed to me</option>
</select>
)}
{canSilence && shownIds.length > 0 && (
<label className="form-check mb-0">
<input
type="checkbox"
className="form-check-input"
checked={allShownPicked}
onChange={(e) =>
setPicked((prev) => {
const next = new Set(prev);
for (const id of shownIds) {
if (e.target.checked) next.add(id);
else next.delete(id);
}
return next;
})
}
/>
<span className="form-check-label">Pick all {shownIds.length} shown</span>
</label>
)}
{(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)} />
@@ -356,12 +423,20 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
<Fragment key={a.id}>
<tr className={`alert-row alert-row-${a.severity}${a.silenced ? " text-secondary" : ""}`} style={a.silenced ? { opacity: 0.65 } : undefined}>
<td>
{canSilence && (
<input type="checkbox" className="form-check-input me-2 align-middle" aria-label={`Pick: ${a.message}`} checked={picked.has(a.id)} onChange={() => togglePicked(a.id)} />
)}
<span className={`badge ${SEVERITY[a.severity].badge}`}>{SEVERITY[a.severity].label}</span>
</td>
<td>{CATEGORY_LABELS[a.category]}</td>
<td>{a.link ? <Link to={a.link}>{a.source}</Link> : a.source}</td>
<td className="stack-wide">
{a.message}
{a.flapping && (
<span className="badge bg-red-lt text-red ms-2" title="Raised and cleared again and again within an hour — its messages are held back until it has been calm for an hour">
flapping
</span>
)}
{a.causedBy ? (
<span className="badge bg-secondary-lt text-secondary ms-2" title={`${a.causedBy.name} is down too, which explains this — notifications for this are held back. If ${a.causedBy.name} comes back and this stays down, it alerts then.`}>
caused by {a.causedBy.name}
@@ -473,6 +548,25 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
</>
)}
{canSilence && pickedIds.length > 0 && (
<>
<div className="has-bulk-bar" />
<BulkBar count={pickedIds.length} noun={pickedIds.length === 1 ? "alert" : "alerts"} onClear={() => setPicked(new Set())}>
<button type="button" className="btn btn-sm btn-primary" onClick={() => setBulkForm("ack")}>
Acknowledge…
</button>
<button type="button" className="btn btn-sm" onClick={() => void bulkUnack()}>
Remove acknowledgement
</button>
<button type="button" className="btn btn-sm" onClick={() => setBulkForm("silence")}>
Silence…
</button>
</BulkBar>
</>
)}
{bulkForm === "ack" && <AckBulkDrawer count={pickedIds.length} onSubmit={bulkAck} onClose={() => setBulkForm(null)} />}
{bulkForm === "silence" && <SilenceBulkDrawer noun={pickedIds.length === 1 ? "alert" : "alerts"} count={pickedIds.length} canSilenceDependents={false} onSubmit={bulkSilence} onClose={() => setBulkForm(null)} />}
{acking && <AckDrawer alert={acking} me={user} onClose={() => setAcking(null)} onSaved={() => {
void load(true);
reloadBadge();
+63
View File
@@ -16,6 +16,9 @@ import { readableError } from "../utils/errors";
import { KIND_HINTS, KIND_LABELS, money, warrantyDays, warrantyState, yearlyCost, yearlyKwh } from "../utils/inventory";
import { toast } from "../utils/toast";
import { EmptyRow } from "../components/EmptyState";
import BulkBar from "../components/BulkBar";
import { HardwareBulkDrawer } from "../components/BulkDrawers";
import { doBulk, plural } from "../utils/bulk";
const KINDS = Object.keys(KIND_LABELS) as AssetKind[];
@@ -114,6 +117,9 @@ export default function Inventory({ user }: { user: CurrentUser }) {
const [busy, setBusy] = useState(false);
const [priceText, setPriceText] = useState("");
const [currencyText, setCurrencyText] = useState("");
// Hardware ticked for a change in one go, and whether that form is open.
const [picked, setPicked] = useState<Set<number>>(new Set());
const [bulkOpen, setBulkOpen] = useState(false);
const [params, setParams] = useSearchParams();
const kind = (KINDS as string[]).includes(params.get("kind") ?? "") ? (params.get("kind") as AssetKind) : "";
@@ -166,6 +172,25 @@ export default function Inventory({ user }: { user: CurrentUser }) {
}
}
const pickedIds = (assets ?? []).filter((a) => picked.has(a.id)).map((a) => a.id);
const shownIds = (sorted ?? []).map((a) => a.id);
const allShownPicked = shownIds.length > 0 && shownIds.every((id) => picked.has(id));
function togglePicked(id: number) {
setPicked((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
async function bulkChange(change: { location?: string | null; warrantyUntil?: string | null; endOfSupport?: string | null }) {
const r = await doBulk({ call: api.bulk.inventory, body: { action: "change", ids: pickedIds, ...change }, done: (res) => `${plural(res.changed, "piece")} of hardware changed.`, reload: load });
if (r) {
setBulkOpen(false);
setPicked(new Set());
}
}
async function remove(a: Asset) {
if (!(await confirmDialog({ title: "Remove from the inventory", message: `Remove "${a.name}"?`, confirmLabel: "Remove", danger: true }))) return;
try {
@@ -459,6 +484,27 @@ export default function Inventory({ user }: { user: CurrentUser }) {
onSearch={tableSearch.setQuery}
placeholder="Search hardware…"
filters={
<>
{canEdit && shownIds.length > 0 && (
<label className="form-check mb-0">
<input
type="checkbox"
className="form-check-input"
checked={allShownPicked}
onChange={(e) =>
setPicked((prev) => {
const next = new Set(prev);
for (const id of shownIds) {
if (e.target.checked) next.add(id);
else next.delete(id);
}
return next;
})
}
/>
<span className="form-check-label">Pick all {shownIds.length} shown</span>
</label>
)}
<select
className="form-select form-select-sm w-auto"
aria-label="Show hardware of kind"
@@ -482,6 +528,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
</option>
))}
</select>
</>
}
shown={sorted?.length}
total={all.length}
@@ -512,6 +559,7 @@ export default function Inventory({ user }: { user: CurrentUser }) {
{page.pageItems?.map((a) => (
<tr key={a.id}>
<td className="stack-wide">
{canEdit && <input type="checkbox" className="form-check-input me-2 align-middle" aria-label={`Pick ${a.name}`} checked={picked.has(a.id)} onChange={() => togglePicked(a.id)} />}
{a.name}
{(a.manufacturer || a.model) && <div className="text-secondary small">{[a.manufacturer, a.model].filter(Boolean).join(" ")}</div>}
{a.server && (
@@ -565,6 +613,21 @@ export default function Inventory({ user }: { user: CurrentUser }) {
<Pagination page={page.page} pageCount={page.pageCount} totalCount={page.totalCount} onPageChange={page.setPage} />
</div>
{canEdit && pickedIds.length > 0 && (
<>
<div className="has-bulk-bar" />
<BulkBar count={pickedIds.length} noun={pickedIds.length === 1 ? "piece" : "pieces"} onClear={() => setPicked(new Set())}>
<button type="button" className="btn btn-sm btn-primary" onClick={() => setBulkOpen(true)}>
Change where / dates…
</button>
<Link to={`/inventory/labels?only=${pickedIds.join(",")}`} className="btn btn-sm">
Print labels
</Link>
</BulkBar>
</>
)}
{bulkOpen && <HardwareBulkDrawer count={pickedIds.length} onSubmit={bulkChange} onClose={() => setBulkOpen(false)} />}
{isAdmin && (
<form className="card" onSubmit={saveConfig}>
<div className="card-header">
+4 -2
View File
@@ -30,14 +30,16 @@ export default function InventoryLabels() {
const [showBorder, setShowBorder] = useState(true);
// From the command palette (?only=ID): start with just that piece of hardware ticked.
const [params] = useSearchParams();
const only = /^\d+$/.test(params.get("only") ?? "") ? Number(params.get("only")) : null;
// ?only=1,2,3 starts with those ticked (the Inventory page's "Print labels" for the pieces picked there).
const only = (params.get("only") ?? "").split(",").filter((v) => /^\d+$/.test(v)).map(Number);
useEffect(() => {
api.inventory
.list()
.then((res) => {
setAssets(res.assets);
setChosen(new Set(only !== null && res.assets.some((a) => a.id === only) ? [only] : res.assets.map((a) => a.id)));
const wanted = res.assets.filter((a) => only.includes(a.id)).map((a) => a.id);
setChosen(new Set(wanted.length > 0 ? wanted : res.assets.map((a) => a.id)));
})
.catch((err) => setError(readableError(err)));
// eslint-disable-next-line react-hooks/exhaustive-deps
+126 -1
View File
@@ -23,6 +23,9 @@ import SaveViewButton from "../components/SaveViewButton";
import { agentState } from "../utils/agent";
import { BlockSkeleton } from "../components/Skeleton";
import EmptyState, { EmptyRow, LoadingRow } from "../components/EmptyState";
import BulkBar from "../components/BulkBar";
import { RunsOnBulkDrawer, SilenceBulkDrawer, TagBulkDrawer } from "../components/BulkDrawers";
import { doBulk, plural } from "../utils/bulk";
function typeBadgeStyle(colors: Record<string, string>, type: string): CSSProperties {
const color = colors[type];
@@ -53,6 +56,10 @@ export default function Servers({ user }: { user: CurrentUser }) {
// Picking servers to compare their trends side by side.
const [comparing, setComparing] = useState(false);
const [picked, setPicked] = useState<number[]>([]);
// Picking servers to change several at once (tags, maintenance, what they run on), and which form is open.
const [selecting, setSelecting] = useState(false);
const [chosen, setChosen] = useState<Set<number>>(new Set());
const [bulkForm, setBulkForm] = useState<"tag" | "silence" | "runson" | null>(null);
const tagColors = useTagColors();
useEffect(() => {
@@ -188,6 +195,8 @@ export default function Servers({ user }: { user: CurrentUser }) {
changeParams((next) => (value ? next.set("status", value) : next.delete("status")));
}
// Operators and administrators can change several servers at once; a viewer only looks.
const canChange = user.role === "admin" || user.role === "operator";
const MAX_COMPARE = 4;
function togglePicked(id: number) {
setPicked((prev) => (prev.includes(id) ? prev.filter((x) => x !== id) : prev.length >= MAX_COMPARE ? prev : [...prev, id]));
@@ -196,6 +205,27 @@ export default function Servers({ user }: { user: CurrentUser }) {
setComparing(false);
setPicked([]);
}
function stopSelecting() {
setSelecting(false);
setChosen(new Set());
setBulkForm(null);
}
function toggleChosen(id: number) {
setChosen((prev) => {
const next = new Set(prev);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
const chosenIds = servers.filter((s) => chosen.has(s.id)).map((s) => s.id);
async function runBulk(body: Record<string, unknown>, done: (changed: number) => string): Promise<void> {
const r = await doBulk({ call: api.bulk.servers, body, done: (res) => done(res.changed), reload: () => void loadServers() });
if (r) {
setBulkForm(null);
setChosen(new Set());
}
}
const cardBody = (s: ServerRecord) => (
<div className="card-body">
@@ -505,10 +535,37 @@ export default function Servers({ user }: { user: CurrentUser }) {
<div className="ms-auto d-flex flex-wrap gap-2">
<SaveViewButton />
{servers.length > 1 && (
<button type="button" className={`btn btn-sm ${comparing ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={comparing} onClick={() => (comparing ? stopComparing() : setComparing(true))}>
<button
type="button"
className={`btn btn-sm ${comparing ? "btn-primary" : "btn-outline-secondary"}`}
aria-pressed={comparing}
onClick={() => {
if (comparing) stopComparing();
else {
stopSelecting();
setComparing(true);
}
}}
>
Compare
</button>
)}
{canChange && (
<button
type="button"
className={`btn btn-sm ${selecting ? "btn-primary" : "btn-outline-secondary"}`}
aria-pressed={selecting}
onClick={() => {
if (selecting) stopSelecting();
else {
stopComparing();
setSelecting(true);
}
}}
>
Select
</button>
)}
</div>
</div>
{comparing && (
@@ -532,6 +589,19 @@ export default function Servers({ user }: { user: CurrentUser }) {
</div>
</div>
)}
{selecting && (
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2" role="status">
<span>Pick the servers to change together, then choose what to do from the bar at the foot of the page. {chosenIds.length} picked.</span>
<div className="ms-auto d-flex gap-2">
<button type="button" className="btn btn-sm" onClick={() => setChosen(new Set(visibleServers.map((s) => s.id)))} disabled={visibleServers.length === 0}>
Pick all {visibleServers.length} shown
</button>
<button type="button" className="btn btn-sm" onClick={stopSelecting}>
Done
</button>
</div>
</div>
)}
{allTags.length > 0 && (
<div className="d-flex flex-wrap align-items-center gap-1 mb-3">
<span className="text-secondary small me-1">Tags</span>
@@ -579,6 +649,15 @@ export default function Servers({ user }: { user: CurrentUser }) {
>
{cardBody(s)}
</button>
) : selecting ? (
<button
type="button"
className={`card card-sm text-reset text-start w-100 compare-card ${chosen.has(s.id) ? "compare-card-on" : ""}`}
aria-pressed={chosen.has(s.id)}
onClick={() => toggleChosen(s.id)}
>
{cardBody(s)}
</button>
) : (
<Link to={`/servers/${s.id}`} className="card card-sm text-reset text-decoration-none">
{cardBody(s)}
@@ -589,6 +668,52 @@ export default function Servers({ user }: { user: CurrentUser }) {
</div>
</>
)}
{selecting && chosenIds.length > 0 && (
<>
<div className="has-bulk-bar" />
<BulkBar count={chosenIds.length} noun={chosenIds.length === 1 ? "server" : "servers"} onClear={() => setChosen(new Set())}>
<button type="button" className="btn btn-sm btn-primary" onClick={() => setBulkForm("tag")}>
Tag…
</button>
<button type="button" className="btn btn-sm" onClick={() => setBulkForm("silence")}>
Silence…
</button>
{isAdmin && (
<button type="button" className="btn btn-sm" onClick={() => setBulkForm("runson")}>
Runs on…
</button>
)}
</BulkBar>
</>
)}
{bulkForm === "tag" && (
<TagBulkDrawer
count={chosenIds.length}
tags={allTags}
onClose={() => setBulkForm(null)}
onSubmit={(v) =>
runBulk({ action: v.mode === "add" ? "add_tag" : "remove_tag", ids: chosenIds, tag: v.tag }, (n) => (v.mode === "add" ? `Tagged ${plural(n, "server")} ${v.tag}.` : `Took ${v.tag} off ${plural(n, "server")}.`))
}
/>
)}
{bulkForm === "silence" && (
<SilenceBulkDrawer
noun={chosenIds.length === 1 ? "server" : "servers"}
count={chosenIds.length}
canSilenceDependents
onClose={() => setBulkForm(null)}
onSubmit={(v) => runBulk({ action: "silence", ids: chosenIds, ...v }, (n) => `${plural(n, "server")} put under maintenance.`)}
/>
)}
{bulkForm === "runson" && (
<RunsOnBulkDrawer
count={chosenIds.length}
servers={servers.filter((s) => !chosen.has(s.id)).map((s) => ({ id: s.id, name: s.name }))}
onClose={() => setBulkForm(null)}
onSubmit={(parentServerId) => runBulk({ action: "set_parent", ids: chosenIds, parentServerId }, (n) => `${plural(n, "server")} changed.`)}
/>
)}
</>
);
}
@@ -82,7 +82,7 @@ const DIGEST_DAYS: { value: number; label: string }[] = [
{ value: 6, label: "Saturday" },
{ value: 0, label: "Sunday" },
];
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true };
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true, flapRaises: 3 };
const DEFAULT_MONTHLY: MonthlyReportSettings = { enabled: false, day: 1, time: "08:00" };
type TestResult = { ok: boolean; message: string } | null;
@@ -745,6 +745,17 @@ export default function NotificationSettings() {
</span>
</span>
</label>
<div className="mt-3">
<NumberField
label="Call an alert flapping after"
value={healthChecks.flapRaises}
min={0}
max={20}
unit="raises in an hour"
hint="An alert that is raised and clears this many times within an hour sends one “flapping” message and then stays quiet until it has been calm for an hour, when one message says whether it is still active. Webhooks that receive every event still get every raise and clear. 0 turns it off."
onChange={(v) => setHealthChecks((h) => ({ ...h, flapRaises: v }))}
/>
</div>
</div>
</div>
</div>