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:
1 parent
be6c5552bd
commit
73a06ebe63
35 files changed
+2546
-17
No files matched your search
@@ -0,0 +1,285 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { api } from "../api/client";
|
||||
import DetailDrawer from "./DetailDrawer";
|
||||
|
||||
/** The little forms behind the bulk bar: each says what will be done and to how many, collects the one or two answers it needs, and hands them back. */
|
||||
|
||||
function Shell({ title, subtitle, onClose, onSubmit, submitLabel, busy, disabled, children }: { title: string; subtitle: string; onClose: () => void; onSubmit: () => void; submitLabel: string; busy: boolean; disabled?: boolean; children: ReactNode }) {
|
||||
return (
|
||||
<DetailDrawer title={title} subtitle={subtitle} onClose={onClose}>
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
onSubmit();
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
<div className="d-flex gap-2 mt-3">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || disabled}>
|
||||
{busy ? "Working…" : submitLabel}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
<div className="text-secondary small mt-2">Afterwards there is an Undo button for a little while; it puts back what was changed.</div>
|
||||
</form>
|
||||
</DetailDrawer>
|
||||
);
|
||||
}
|
||||
|
||||
const MINUTES = [
|
||||
{ minutes: 30, label: "30 minutes" },
|
||||
{ minutes: 60, label: "1 hour" },
|
||||
{ minutes: 180, label: "3 hours" },
|
||||
{ minutes: 480, label: "8 hours" },
|
||||
{ minutes: 1440, label: "1 day" },
|
||||
{ minutes: 4320, label: "3 days" },
|
||||
];
|
||||
|
||||
/** Maintenance on everything picked: for how long, and why. */
|
||||
export function SilenceBulkDrawer({ noun, count, canSilenceDependents, onSubmit, onClose }: { noun: string; count: number; canSilenceDependents: boolean; onSubmit: (v: { minutes: number; reason: string; withDependents: boolean }) => Promise<void>; onClose: () => void }) {
|
||||
const [minutes, setMinutes] = useState(60);
|
||||
const [reason, setReason] = useState("");
|
||||
const [withDependents, setWithDependents] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
<Shell
|
||||
title="Put under maintenance"
|
||||
subtitle={`${count} ${noun}`}
|
||||
onClose={onClose}
|
||||
busy={busy}
|
||||
submitLabel="Start maintenance"
|
||||
onSubmit={async () => {
|
||||
setBusy(true);
|
||||
await onSubmit({ minutes, reason: reason.trim(), withDependents });
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<p className="text-secondary">Alerts about each are held back for this long; anything still wrong when it ends alerts then. One already under maintenance has its time restarted.</p>
|
||||
<label className="form-label" htmlFor="bulk-min">
|
||||
For
|
||||
</label>
|
||||
<select id="bulk-min" className="form-select mb-3" value={minutes} onChange={(e) => setMinutes(Number(e.target.value))}>
|
||||
{MINUTES.map((m) => (
|
||||
<option key={m.minutes} value={m.minutes}>
|
||||
{m.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<label className="form-label" htmlFor="bulk-reason">
|
||||
Why <span className="text-secondary">(optional)</span>
|
||||
</label>
|
||||
<input id="bulk-reason" className="form-control mb-3" maxLength={200} value={reason} onChange={(e) => setReason(e.target.value)} placeholder="e.g. Firmware update" />
|
||||
{canSilenceDependents && (
|
||||
<label className="form-check">
|
||||
<input type="checkbox" className="form-check-input" checked={withDependents} onChange={(e) => setWithDependents(e.target.checked)} />
|
||||
<span className="form-check-label">Also silence what depends on them (a guest that runs on one, a service that needs one)</span>
|
||||
</label>
|
||||
)}
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
const LENGTHS: { hours: number | null; label: string }[] = [
|
||||
{ hours: null, label: "Until the alert is gone" },
|
||||
{ hours: 1, label: "1 hour" },
|
||||
{ hours: 4, label: "4 hours" },
|
||||
{ hours: 24, label: "1 day" },
|
||||
{ hours: 72, label: "3 days" },
|
||||
{ hours: 168, label: "1 week" },
|
||||
];
|
||||
|
||||
/** "I'm on these": the same note, person and length for every alert picked. */
|
||||
export function AckBulkDrawer({ count, onSubmit, onClose }: { count: number; onSubmit: (v: { note: string; assigneeId: number | null; hours: number | null }) => Promise<void>; onClose: () => void }) {
|
||||
const [note, setNote] = useState("");
|
||||
const [assignee, setAssignee] = useState("");
|
||||
const [hours, setHours] = useState("");
|
||||
const [people, setPeople] = useState<{ id: number; name: string }[]>([]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.alerts
|
||||
.assignees()
|
||||
.then((res) => alive && setPeople(res.users))
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
return (
|
||||
<Shell
|
||||
title="Acknowledge"
|
||||
subtitle={`${count} alert${count === 1 ? "" : "s"}`}
|
||||
onClose={onClose}
|
||||
busy={busy}
|
||||
submitLabel="Acknowledge them"
|
||||
onSubmit={async () => {
|
||||
setBusy(true);
|
||||
await onSubmit({ note: note.trim(), assigneeId: assignee === "" ? null : Number(assignee), hours: hours === "" ? null : Number(hours) });
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<p className="text-secondary">Says that somebody has seen them. The alerts stay, and are still counted by /metrics, but they are no longer ones nobody has looked at. One that was already acknowledged has its note replaced.</p>
|
||||
<label className="form-label" htmlFor="bulk-note">
|
||||
Note <span className="text-secondary">(optional)</span>
|
||||
</label>
|
||||
<textarea id="bulk-note" className="form-control mb-3" rows={3} maxLength={500} value={note} onChange={(e) => setNote(e.target.value)} placeholder="e.g. The UPS is being swapped on Saturday" />
|
||||
<label className="form-label" htmlFor="bulk-assignee">
|
||||
Who has them
|
||||
</label>
|
||||
<select id="bulk-assignee" className="form-select mb-3" value={assignee} onChange={(e) => setAssignee(e.target.value)}>
|
||||
<option value="">Nobody in particular</option>
|
||||
{people.map((p) => (
|
||||
<option key={p.id} value={p.id}>
|
||||
{p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<label className="form-label" htmlFor="bulk-hours">
|
||||
For how long
|
||||
</label>
|
||||
<select id="bulk-hours" className="form-select" value={hours} onChange={(e) => setHours(e.target.value)}>
|
||||
{LENGTHS.map((l) => (
|
||||
<option key={l.label} value={l.hours ?? ""}>
|
||||
{l.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
/** Add a tag to, or take one off, every server picked. */
|
||||
export function TagBulkDrawer({ count, tags, onSubmit, onClose }: { count: number; tags: string[]; onSubmit: (v: { mode: "add" | "remove"; tag: string }) => Promise<void>; onClose: () => void }) {
|
||||
const [mode, setMode] = useState<"add" | "remove">("add");
|
||||
const [tag, setTag] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
<Shell
|
||||
title="Tags"
|
||||
subtitle={`${count} server${count === 1 ? "" : "s"}`}
|
||||
onClose={onClose}
|
||||
busy={busy}
|
||||
disabled={tag.trim() === ""}
|
||||
submitLabel={mode === "add" ? "Add the tag" : "Take the tag off"}
|
||||
onSubmit={async () => {
|
||||
setBusy(true);
|
||||
await onSubmit({ mode, tag: tag.trim() });
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<div className="btn-group mb-3" role="group" aria-label="Add or take off">
|
||||
<button type="button" className={`btn ${mode === "add" ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={mode === "add"} onClick={() => setMode("add")}>
|
||||
Add a tag
|
||||
</button>
|
||||
<button type="button" className={`btn ${mode === "remove" ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={mode === "remove"} onClick={() => setMode("remove")}>
|
||||
Take a tag off
|
||||
</button>
|
||||
</div>
|
||||
<label className="form-label" htmlFor="bulk-tag">
|
||||
Tag
|
||||
</label>
|
||||
<input id="bulk-tag" className="form-control" list="bulk-tags" maxLength={30} value={tag} onChange={(e) => setTag(e.target.value)} placeholder="e.g. lab" autoFocus />
|
||||
<datalist id="bulk-tags">
|
||||
{tags.map((t) => (
|
||||
<option key={t} value={t} />
|
||||
))}
|
||||
</datalist>
|
||||
<div className="form-hint text-secondary small mt-2">Written the way tags always are (lower case, no spaces). A server that already has it, or lacks it, is left as it is.</div>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
/** Which server every server picked runs on (or back to working it out). */
|
||||
export function RunsOnBulkDrawer({ count, servers, onSubmit, onClose }: { count: number; servers: { id: number; name: string }[]; onSubmit: (parentServerId: number | null) => Promise<void>; onClose: () => void }) {
|
||||
const [choice, setChoice] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
return (
|
||||
<Shell
|
||||
title="Runs on"
|
||||
subtitle={`${count} server${count === 1 ? "" : "s"}`}
|
||||
onClose={onClose}
|
||||
busy={busy}
|
||||
disabled={choice === ""}
|
||||
submitLabel="Set it"
|
||||
onSubmit={async () => {
|
||||
setBusy(true);
|
||||
await onSubmit(choice === "auto" ? null : Number(choice));
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<p className="text-secondary">When the server they run on is down, their own offline alerts are folded under its alert instead of adding to the noise. A change that would make a loop is left out.</p>
|
||||
<label className="form-label" htmlFor="bulk-parent">
|
||||
They run on
|
||||
</label>
|
||||
<select id="bulk-parent" className="form-select" value={choice} onChange={(e) => setChoice(e.target.value)}>
|
||||
<option value="">Choose…</option>
|
||||
<option value="auto">Work it out from the Proxmox node (the default)</option>
|
||||
{servers.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
|
||||
type Field = { mode: "keep" | "set" | "clear"; value: string };
|
||||
const KEEP: Field = { mode: "keep", value: "" };
|
||||
|
||||
function FieldChange({ id, label, type, value, onChange }: { id: string; label: string; type: "text" | "date"; value: Field; onChange: (v: Field) => void }) {
|
||||
return (
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor={id}>
|
||||
{label}
|
||||
</label>
|
||||
<div className="d-flex gap-2">
|
||||
<select aria-label={`${label}: what to do`} className="form-select w-auto" value={value.mode} onChange={(e) => onChange({ ...value, mode: e.target.value as Field["mode"] })}>
|
||||
<option value="keep">Leave as it is</option>
|
||||
<option value="set">Set to…</option>
|
||||
<option value="clear">Clear</option>
|
||||
</select>
|
||||
{value.mode === "set" && <input id={id} type={type} className="form-control" maxLength={120} value={value.value} onChange={(e) => onChange({ ...value, value: e.target.value })} required />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Where it is, and when it is covered and supported — for every piece of hardware picked. */
|
||||
export function HardwareBulkDrawer({ count, onSubmit, onClose }: { count: number; onSubmit: (v: { location?: string | null; warrantyUntil?: string | null; endOfSupport?: string | null }) => Promise<void>; onClose: () => void }) {
|
||||
const [location, setLocation] = useState<Field>(KEEP);
|
||||
const [warranty, setWarranty] = useState<Field>(KEEP);
|
||||
const [support, setSupport] = useState<Field>(KEEP);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const apply = (f: Field) => (f.mode === "keep" ? undefined : f.mode === "clear" ? null : f.value.trim());
|
||||
const nothing = location.mode === "keep" && warranty.mode === "keep" && support.mode === "keep";
|
||||
return (
|
||||
<Shell
|
||||
title="Change hardware"
|
||||
subtitle={`${count} piece${count === 1 ? "" : "s"}`}
|
||||
onClose={onClose}
|
||||
busy={busy}
|
||||
disabled={nothing}
|
||||
submitLabel="Change them"
|
||||
onSubmit={async () => {
|
||||
setBusy(true);
|
||||
const change: { location?: string | null; warrantyUntil?: string | null; endOfSupport?: string | null } = {};
|
||||
const l = apply(location);
|
||||
const w = apply(warranty);
|
||||
const s = apply(support);
|
||||
if (l !== undefined) change.location = l;
|
||||
if (w !== undefined) change.warrantyUntil = w;
|
||||
if (s !== undefined) change.endOfSupport = s;
|
||||
await onSubmit(change);
|
||||
setBusy(false);
|
||||
}}
|
||||
>
|
||||
<p className="text-secondary">Whatever is left as it is stays the way each one has it.</p>
|
||||
<FieldChange id="bulk-location" label="Where it is" type="text" value={location} onChange={setLocation} />
|
||||
<FieldChange id="bulk-warranty" label="Warranty until" type="date" value={warranty} onChange={setWarranty} />
|
||||
<FieldChange id="bulk-support" label="End of support" type="date" value={support} onChange={setSupport} />
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user