Acknowledge and hand over alerts, incident timelines, and built-in database backups
- Alerts can be acknowledged (note, assignee, duration); acknowledged alerts are left out of what needs attention (sidebar, dashboard strip, cards) but stay raised and counted by /metrics - Incidents: each time an alert is raised and goes away is recorded (alert_acks, alert_incidents, incident_notes, migration 0032), with a timeline of acks, maintenance, changes, update runs, related alerts and notes; Incidents page and a digest section - Backups of Homelab Manager's own database: daily checked VACUUM INTO copies, retention, download, check, upload, delete, and restore staged and applied at start-up before the database opens (pre-restore copy kept); alerts and /metrics for stale or failing backups - Docs: README, BACKUP, DATABASE, NOTIFICATIONS, ROLES, API; tests Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a5b623444
commit
2744a84719
41 files changed
+6573
-26
No files matched your search
@@ -0,0 +1,253 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { IconAlertTriangle, IconBell, IconCheck, IconClockPause, IconHandStop, IconLink, IconNote, IconPlayerPlay, IconSettings } from "@tabler/icons-react";
|
||||
import { api, type CurrentUser, type IncidentDetail as Detail, type TimelineEvent, type TimelineKind } from "../api/client";
|
||||
import { ackWords } from "../components/AckDrawer";
|
||||
import RunbookEntry from "../components/RunbookEntry";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { CATEGORY_NAMES, durationWords, SEVERITY_BADGE } from "./Incidents";
|
||||
|
||||
const KIND_ICON: Record<TimelineKind, JSX.Element> = {
|
||||
alert: <IconAlertTriangle size={16} />,
|
||||
ack: <IconHandStop size={16} />,
|
||||
maintenance: <IconClockPause size={16} />,
|
||||
change: <IconSettings size={16} />,
|
||||
health: <IconBell size={16} />,
|
||||
run: <IconPlayerPlay size={16} />,
|
||||
related: <IconLink size={16} />,
|
||||
note: <IconNote size={16} />,
|
||||
};
|
||||
|
||||
const TONE_COLOR: Record<TimelineEvent["tone"], string> = { good: "bg-green-lt text-green", bad: "bg-red-lt text-red", neutral: "bg-secondary-lt text-secondary", info: "bg-blue-lt text-blue" };
|
||||
|
||||
/** One incident, with everything the app knows about the time around it in the order it happened, and a place for notes. */
|
||||
export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
const { id: idParam } = useParams();
|
||||
const id = Number(idParam);
|
||||
const canWrite = user.role === "admin" || user.role === "operator";
|
||||
const [detail, setDetail] = useState<Detail | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [missing, setMissing] = useState(false);
|
||||
const [note, setNote] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const load = useCallback(() => {
|
||||
if (!Number.isInteger(id)) {
|
||||
setMissing(true);
|
||||
return Promise.resolve();
|
||||
}
|
||||
return api.incidents
|
||||
.get(id)
|
||||
.then((d) => {
|
||||
setDetail(d);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (/\((404|400)\)/.test(String(err))) setMissing(true);
|
||||
else setError(readableError(err));
|
||||
});
|
||||
}, [id]);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
// While it is open the picture is still changing.
|
||||
const open = detail?.incident.open ?? false;
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const timer = setInterval(() => void load(), 30_000);
|
||||
return () => clearInterval(timer);
|
||||
}, [open, load]);
|
||||
|
||||
async function addNote() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.incidents.addNote(id, note.trim());
|
||||
setNote("");
|
||||
await load();
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function removeNote(noteId: number) {
|
||||
if (!(await confirmDialog({ title: "Remove this note?", message: "It is taken out of the incident's history.", confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.incidents.removeNote(id, noteId);
|
||||
await load();
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
if (missing) {
|
||||
return (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary">
|
||||
There is no incident like that (it may be old enough to have been removed). <Link to="/incidents">All incidents</Link>.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!detail) {
|
||||
return (
|
||||
<>
|
||||
<ErrorNotice error={error} />
|
||||
<BlockSkeleton lines={6} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const { incident, ack, timeline } = detail;
|
||||
const target = incident.target;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mb-2">
|
||||
<Link to="/incidents" className="text-secondary">
|
||||
← Incidents
|
||||
</Link>
|
||||
</div>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<h2 className="page-title mb-0">{incident.message}</h2>
|
||||
</div>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
|
||||
{incident.open ? <span className="badge bg-red-lt text-red">open</span> : <span className="badge bg-green-lt text-green">resolved</span>}
|
||||
<span className={`badge ${SEVERITY_BADGE[incident.peakSeverity] ?? ""}`}>{incident.peakSeverity}</span>
|
||||
<span className="text-secondary">{CATEGORY_NAMES[incident.category] ?? incident.category}</span>
|
||||
{incident.causedBy && <span className="badge bg-secondary-lt text-secondary">caused by {incident.causedBy}</span>}
|
||||
{target && (
|
||||
<span className="text-secondary">
|
||||
· {target.type === "server" ? <Link to={`/servers/${target.id}`}>{target.name}</Link> : target.name}
|
||||
</span>
|
||||
)}
|
||||
{target && <RunbookEntry targetType={target.type} targetId={target.id} targetName={target.name} canEdit={canWrite} forCategory={incident.category} />}
|
||||
{incident.open && (
|
||||
<Link to="/alerts" className="ms-auto">
|
||||
Open in Alerts
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="h3 mb-0" title={formatDateTime(new Date(incident.openedAt))}>
|
||||
<TimeAgo value={incident.openedAt} />
|
||||
</div>
|
||||
<div className="text-secondary">Began</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="h3 mb-0">{durationWords(incident.durationMs)}</div>
|
||||
<div className="text-secondary">{incident.open ? "So far" : "Lasted"}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="h3 mb-0">{incident.resolvedAt ? <TimeAgo value={incident.resolvedAt} /> : "—"}</div>
|
||||
<div className="text-secondary">Ended</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-lg-3">
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className="h3 mb-0">{incident.notes}</div>
|
||||
<div className="text-secondary">{incident.notes === 1 ? "Note" : "Notes"}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{ack && (
|
||||
<div className={`alert ${ack.active ? "alert-info" : "alert-secondary"}`}>
|
||||
<div>
|
||||
<strong>{ack.active ? ackWords(ack) : "Its acknowledgement has run out"}</strong>
|
||||
{ack.note && <div>{ack.note}</div>}
|
||||
<div className="small">
|
||||
Acknowledged by {ack.ackedBy} <TimeAgo value={ack.ackedAt} />.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="row g-3">
|
||||
<div className="col-lg-8">
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">What happened</h3>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{timeline.map((e, i) => (
|
||||
<div className="list-group-item" key={`${e.at}-${i}`}>
|
||||
<div className="d-flex gap-3">
|
||||
<span className={`badge ${TONE_COLOR[e.tone]} flex-shrink-0 align-self-start`} style={{ width: 28, height: 28, display: "inline-flex", alignItems: "center", justifyContent: "center" }}>
|
||||
{KIND_ICON[e.kind] ?? <IconCheck size={16} />}
|
||||
</span>
|
||||
<div className="flex-fill">
|
||||
<div className="d-flex flex-wrap gap-2 align-items-baseline">
|
||||
<strong>{e.incidentId ? <Link to={`/incidents/${e.incidentId}`}>{e.title}</Link> : e.title}</strong>
|
||||
<span className="text-secondary small" title={formatDateTime(new Date(e.at))}>
|
||||
{formatDateTime(new Date(e.at))}
|
||||
</span>
|
||||
{e.actor && e.actor !== "system" && <span className="text-secondary small">· {e.actor}</span>}
|
||||
</div>
|
||||
{e.detail && <div className={e.kind === "note" ? "mt-1" : "text-secondary small"} style={e.kind === "note" ? { whiteSpace: "pre-wrap" } : undefined}>{e.detail}</div>}
|
||||
{e.noteId !== undefined && (user.role === "admin" || e.actor === user.name) && (
|
||||
<button type="button" className="btn btn-sm btn-ghost-secondary mt-1" onClick={() => void removeNote(e.noteId!)}>
|
||||
Remove note
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="card-footer text-secondary small">
|
||||
Put together from the alert itself, the audit log, the maintenance windows, update runs and other alerts about the same thing.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Notes</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{detail.notes.length === 0 && <div className="text-secondary mb-3">Nothing written yet. What was it? What fixed it? What would you do differently?</div>}
|
||||
{canWrite ? (
|
||||
<>
|
||||
<textarea className="form-control mb-2" rows={4} maxLength={4000} placeholder="Add a note…" aria-label="Add a note" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||
<button type="button" className="btn btn-primary" disabled={busy || note.trim() === ""} onClick={() => void addNote()}>
|
||||
{busy ? "Saving…" : "Add note"}
|
||||
</button>
|
||||
<div className="form-hint text-secondary small mt-2">It appears in the history on the left, with your name and the time.</div>
|
||||
</>
|
||||
) : (
|
||||
detail.notes.length > 0 && <div className="text-secondary small">Operators can add notes.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user