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
@@ -29,6 +29,8 @@ import Alerts from "./pages/Alerts";
|
||||
import Generator from "./pages/Generator";
|
||||
import Maintenance from "./pages/Maintenance";
|
||||
import Updates from "./pages/Updates";
|
||||
import Incidents from "./pages/Incidents";
|
||||
import IncidentDetail from "./pages/IncidentDetail";
|
||||
import Inventory from "./pages/Inventory";
|
||||
import Backups from "./pages/Backups";
|
||||
import Domains from "./pages/Domains";
|
||||
@@ -155,6 +157,8 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/osticket" element={<OsTicket user={user} />} />
|
||||
<Route path="/admin-links" element={<AdminLinks user={user} />} />
|
||||
<Route path="/alerts" element={<Alerts user={user} />} />
|
||||
<Route path="/incidents" element={<Incidents />} />
|
||||
<Route path="/incidents/:id" element={<IncidentDetail user={user} />} />
|
||||
<Route
|
||||
path="/users"
|
||||
element={
|
||||
|
||||
+139
-1
@@ -805,6 +805,67 @@ export interface AlertItem {
|
||||
affects?: string[];
|
||||
/** The osTicket ticket opened for it, if one was. */
|
||||
ticket?: { number: string | null; url: string | null; grouped: boolean; openedAt: string | null } | null;
|
||||
/** Somebody has said they are on it. */
|
||||
ack?: AlertAck | null;
|
||||
/** The incident record this alert is part of, while it lasts. */
|
||||
incidentId?: number | null;
|
||||
}
|
||||
|
||||
export interface AlertAck {
|
||||
note: string;
|
||||
assignee: { id: number | null; name: string } | null;
|
||||
ackedBy: string;
|
||||
ackedAt: string;
|
||||
/** ISO — when it runs out; null means it lasts until the alert is gone. */
|
||||
until: string | null;
|
||||
/** Still in force. */
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface AckInput {
|
||||
alertId: string;
|
||||
note: string;
|
||||
assigneeId: number | null;
|
||||
/** How long it lasts; null is until the alert is gone. */
|
||||
hours: number | null;
|
||||
}
|
||||
|
||||
export type TimelineKind = "alert" | "ack" | "maintenance" | "change" | "health" | "run" | "related" | "note";
|
||||
|
||||
export interface TimelineEvent {
|
||||
at: string;
|
||||
kind: TimelineKind;
|
||||
tone: "good" | "bad" | "neutral" | "info";
|
||||
title: string;
|
||||
detail: string | null;
|
||||
actor: string | null;
|
||||
incidentId?: number;
|
||||
noteId?: number;
|
||||
}
|
||||
|
||||
export interface IncidentSummary {
|
||||
id: number;
|
||||
alertKey: string;
|
||||
severity: string;
|
||||
peakSeverity: string;
|
||||
category: AlertCategory;
|
||||
source: string;
|
||||
message: string;
|
||||
link: string | null;
|
||||
target: { type: MaintenanceTargetType; id: number; name: string } | null;
|
||||
causedBy: string | null;
|
||||
openedAt: string;
|
||||
resolvedAt: string | null;
|
||||
durationMs: number;
|
||||
open: boolean;
|
||||
notes: number;
|
||||
}
|
||||
|
||||
export interface IncidentDetail {
|
||||
incident: IncidentSummary;
|
||||
ack: AlertAck | null;
|
||||
timeline: TimelineEvent[];
|
||||
notes: { id: number; author: string; body: string; at: string }[];
|
||||
}
|
||||
|
||||
export type AlertTicketSeverity = "critical" | "warning" | "info";
|
||||
@@ -844,9 +905,60 @@ export interface AlertTicketOverview {
|
||||
status: { lastRun: AlertTicketRunSummary | null; open: number; pending: number; baseline: number; baselinePending: boolean };
|
||||
}
|
||||
|
||||
export type DbSnapshotKind = "scheduled" | "manual" | "pre-restore" | "uploaded";
|
||||
|
||||
export interface DbSnapshot {
|
||||
name: string;
|
||||
kind: DbSnapshotKind;
|
||||
sizeBytes: number;
|
||||
at: string;
|
||||
}
|
||||
|
||||
export interface DbSnapshotCheck {
|
||||
ok: boolean;
|
||||
integrity: string | null;
|
||||
migrations: number | null;
|
||||
appMigrations: number;
|
||||
newerThanApp: boolean;
|
||||
counts: { users: number; servers: number; integrations: number } | null;
|
||||
problem: string | null;
|
||||
}
|
||||
|
||||
export interface DbBackupSettings {
|
||||
enabled: boolean;
|
||||
time: string;
|
||||
keep: number;
|
||||
}
|
||||
|
||||
export interface DbStagedRestore {
|
||||
from: string;
|
||||
stagedAt: string;
|
||||
by: string | null;
|
||||
}
|
||||
|
||||
export interface DbBackupsOverview {
|
||||
settings: DbBackupSettings;
|
||||
snapshots: DbSnapshot[];
|
||||
staged: DbStagedRestore | null;
|
||||
lastRestore: { restoredAt: string; from: string; keptAs: string | null; by: string | null } | null;
|
||||
lastAttempt: { at: string; ok: boolean; kind: DbSnapshotKind; error: string | null; name: string | null } | null;
|
||||
nextRun: string | null;
|
||||
folder: string;
|
||||
}
|
||||
|
||||
export interface AlertsReport {
|
||||
alerts: AlertItem[];
|
||||
counts: { critical: number; warning: number; info: number; silenced: number; grouped: number };
|
||||
counts: {
|
||||
critical: number;
|
||||
warning: number;
|
||||
info: number;
|
||||
silenced: number;
|
||||
grouped: number;
|
||||
/** Alerts somebody has acknowledged (and that aren't silenced). */
|
||||
acknowledged?: number;
|
||||
/** What still needs somebody to look: the counts above, less what has been acknowledged. */
|
||||
attention?: { critical: number; warning: number };
|
||||
};
|
||||
couldntCheck: { name: string; error: string; affects: string[] }[];
|
||||
notes: string[];
|
||||
generatedAt: string;
|
||||
@@ -1626,6 +1738,32 @@ export const api = {
|
||||
},
|
||||
alerts: {
|
||||
list: (refresh = false) => request<AlertsReport>(`/api/alerts${refresh ? "?refresh=1" : ""}`),
|
||||
assignees: () => request<{ users: { id: number; name: string; role: string }[] }>("/api/alerts/assignees"),
|
||||
ack: (data: AckInput) => request<{ ack: AlertAck }>("/api/alerts/ack", { method: "PUT", body: JSON.stringify(data) }),
|
||||
unack: (alertId: string) => request<void>(`/api/alerts/ack?alertId=${encodeURIComponent(alertId)}`, { method: "DELETE" }),
|
||||
},
|
||||
incidents: {
|
||||
list: () => request<{ incidents: IncidentSummary[] }>("/api/incidents"),
|
||||
get: (id: number) => request<IncidentDetail>(`/api/incidents/${id}`),
|
||||
addNote: (id: number, body: string) => request<{ id: number }>(`/api/incidents/${id}/notes`, { method: "POST", body: JSON.stringify({ body }) }),
|
||||
removeNote: (id: number, noteId: number) => request<void>(`/api/incidents/${id}/notes/${noteId}`, { method: "DELETE" }),
|
||||
},
|
||||
dbBackups: {
|
||||
overview: () => request<DbBackupsOverview>("/api/db-backups"),
|
||||
create: () => request<{ snapshot: DbSnapshot; check: DbSnapshotCheck }>("/api/db-backups", { method: "POST" }),
|
||||
check: (name: string) => request<{ check: DbSnapshotCheck }>(`/api/db-backups/${encodeURIComponent(name)}/check`, { method: "POST" }),
|
||||
restore: (name: string) => request<{ staged: DbStagedRestore | null; check: DbSnapshotCheck }>(`/api/db-backups/${encodeURIComponent(name)}/restore`, { method: "POST" }),
|
||||
cancelRestore: () => request<{ cancelled: boolean }>("/api/db-backups/restore/cancel", { method: "POST" }),
|
||||
dismissRestoreResult: () => request<{ ok: true }>("/api/db-backups/restore-result/dismiss", { method: "POST" }),
|
||||
remove: (name: string) => request<void>(`/api/db-backups/${encodeURIComponent(name)}`, { method: "DELETE" }),
|
||||
saveSettings: (data: DbBackupSettings) => request<DbBackupsOverview>("/api/db-backups/settings", { method: "PUT", body: JSON.stringify(data) }),
|
||||
/** A backup file chosen on this computer, sent as it is. */
|
||||
upload: async (file: File) => {
|
||||
const res = await fetch("/api/db-backups/upload", { method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: file, credentials: "same-origin" });
|
||||
if (!res.ok) throw new Error(await res.text().catch(() => `Upload failed (${res.status})`));
|
||||
return (await res.json()) as { snapshot: DbSnapshot; check: DbSnapshotCheck };
|
||||
},
|
||||
downloadUrl: (name: string) => `/api/db-backups/${encodeURIComponent(name)}/download`,
|
||||
},
|
||||
alertTickets: {
|
||||
get: () => request<AlertTicketOverview>("/api/alert-tickets"),
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type AlertItem, type CurrentUser } from "../api/client";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import DetailDrawer from "./DetailDrawer";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
|
||||
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" },
|
||||
];
|
||||
|
||||
/** What an acknowledgement says, in a few words for a table row: who, and how long it lasts. */
|
||||
export function ackWords(ack: NonNullable<AlertItem["ack"]>): string {
|
||||
const who = ack.assignee ? `${ack.assignee.name} has it` : `${ack.ackedBy} is on it`;
|
||||
return ack.until ? `${who} until ${formatDateTime(new Date(ack.until))}` : who;
|
||||
}
|
||||
|
||||
/**
|
||||
* "I'm on it": say that an alert has been seen, why it is what it is, who has it, and how long it should be left alone. It changes nothing about
|
||||
* the problem (the alert stays, and is still counted by /metrics) but it is no longer one that nobody has looked at.
|
||||
*/
|
||||
export default function AckDrawer({ alert, me, onClose, onSaved }: { alert: AlertItem; me: CurrentUser; onClose: () => void; onSaved: () => void }) {
|
||||
const existing = alert.ack ?? null;
|
||||
const [note, setNote] = useState(existing?.note ?? "");
|
||||
const [assignee, setAssignee] = useState<string>(existing?.assignee?.id ? String(existing.assignee.id) : "");
|
||||
const [hours, setHours] = useState<string>(existing?.until ? "" : "");
|
||||
const [people, setPeople] = useState<{ id: number; name: string }[]>([]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.alerts
|
||||
.assignees()
|
||||
.then((res) => alive && setPeople(res.users))
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
async function save() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api.alerts.ack({ alertId: alert.id, note: note.trim(), assigneeId: assignee === "" ? null : Number(assignee), hours: hours === "" ? null : Number(hours) });
|
||||
toast.success(assignee && Number(assignee) !== me.id ? "Acknowledged and handed over." : "Acknowledged.");
|
||||
onSaved();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function takeBack() {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.alerts.unack(alert.id);
|
||||
toast.success("Acknowledgement taken back.");
|
||||
onSaved();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DetailDrawer title={existing ? "Acknowledgement" : "Acknowledge this alert"} subtitle={alert.source} onClose={onClose}>
|
||||
<div className="mb-3">{alert.message}</div>
|
||||
|
||||
{existing && (
|
||||
<div className="alert alert-info">
|
||||
<div>
|
||||
<strong>{existing.active ? ackWords(existing) : "Its acknowledgement has run out"}</strong>
|
||||
<div className="small">
|
||||
Acknowledged by {existing.ackedBy} <TimeAgo value={existing.ackedAt} />.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ack-note">
|
||||
Note <span className="text-secondary">(optional)</span>
|
||||
</label>
|
||||
<textarea id="ack-note" className="form-control" rows={3} maxLength={500} placeholder="e.g. power cut in the cellar, UPS is holding" value={note} onChange={(e) => setNote(e.target.value)} />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ack-assignee">
|
||||
Who has it
|
||||
</label>
|
||||
<select id="ack-assignee" className="form-select" 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.id === me.id ? `${p.name} (me)` : p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ack-hours">
|
||||
Leave it alone for
|
||||
</label>
|
||||
<select id="ack-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>
|
||||
<div className="form-hint text-secondary small mt-1">After that it counts as unattended again. Either way it goes by itself once the alert has been gone for half an hour.</div>
|
||||
</div>
|
||||
<ErrorNotice error={error} />
|
||||
<div className="d-flex gap-2">
|
||||
<button type="button" className="btn btn-primary" disabled={busy} onClick={() => void save()}>
|
||||
{busy ? "Saving…" : existing ? "Save" : "Acknowledge"}
|
||||
</button>
|
||||
{existing && (
|
||||
<button type="button" className="btn btn-outline-secondary" disabled={busy} onClick={() => void takeBack()}>
|
||||
Take it back
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</DetailDrawer>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { api, type DbBackupSettings, type DbBackupsOverview, type DbSnapshot, type DbSnapshotCheck } from "../api/client";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
|
||||
const KIND_WORDS: Record<DbSnapshot["kind"], { label: string; badge: string; hint: string }> = {
|
||||
scheduled: { label: "daily", badge: "bg-blue-lt text-blue", hint: "Taken by the daily schedule" },
|
||||
manual: { label: "made by hand", badge: "bg-secondary-lt text-secondary", hint: "Taken with Back up now" },
|
||||
"pre-restore": { label: "before a restore", badge: "bg-yellow-lt text-yellow", hint: "The database that was in use when a restore took effect — restore this to undo it" },
|
||||
uploaded: { label: "uploaded", badge: "bg-cyan-lt text-cyan", hint: "A file somebody uploaded" },
|
||||
};
|
||||
|
||||
const size = (bytes: number) => (bytes < 1024 * 1024 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : `${(bytes / 1024 / 1024).toFixed(1)} MB`);
|
||||
|
||||
function CheckResult({ check }: { check: DbSnapshotCheck }) {
|
||||
if (!check.ok) return <span className="text-danger">{check.problem}</span>;
|
||||
return (
|
||||
<span className="text-success">
|
||||
Sound (SQLite says {check.integrity}) — {check.counts ? `${check.counts.users} users, ${check.counts.servers} servers, ${check.counts.integrations} integrations` : "readable"}; schema {check.migrations} of {check.appMigrations}
|
||||
{check.migrations !== null && check.migrations < check.appMigrations ? " (older: brought up to date when restored)" : ""}.
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backups of Homelab Manager's own database: when it was last backed up and when it next will be, a button to make one now, the ones that are
|
||||
* kept (download, check, restore, delete), uploading one from somewhere else, and the daily schedule. A restore is staged here and takes
|
||||
* effect when the app next starts.
|
||||
*/
|
||||
export default function DatabaseBackups() {
|
||||
const [data, setData] = useState<DbBackupsOverview | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [checks, setChecks] = useState<Record<string, DbSnapshotCheck>>({});
|
||||
const [draft, setDraft] = useState<DbBackupSettings | null>(null);
|
||||
const fileRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
return api.dbBackups
|
||||
.overview()
|
||||
.then((d) => {
|
||||
setData(d);
|
||||
setDraft((before) => before ?? d.settings);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
async function run<T>(what: string, work: () => Promise<T>, success?: (r: T) => string) {
|
||||
setBusy(what);
|
||||
setError(null);
|
||||
try {
|
||||
const result = await work();
|
||||
if (success) toast.success(success(result));
|
||||
await load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function restore(s: DbSnapshot) {
|
||||
const ok = await confirmDialog({
|
||||
title: "Restore this backup?",
|
||||
message: `The database becomes the one in ${s.name}, taken ${formatDateTime(new Date(s.at))}, the next time Homelab Manager starts. Anything changed since then — users, edits, the audit log — is replaced by what that backup has. The database in use now is kept as a "before a restore" backup, so this can be undone. Nothing changes until it is restarted.`,
|
||||
confirmLabel: "Stage the restore",
|
||||
danger: true,
|
||||
});
|
||||
if (!ok) return;
|
||||
await run(`restore:${s.name}`, () => api.dbBackups.restore(s.name), () => "The restore is waiting for the next start.");
|
||||
}
|
||||
|
||||
async function remove(s: DbSnapshot) {
|
||||
if (!(await confirmDialog({ title: "Delete this backup?", message: `${s.name} is deleted for good.`, confirmLabel: "Delete", danger: true }))) return;
|
||||
await run(`delete:${s.name}`, () => api.dbBackups.remove(s.name), () => "Deleted.");
|
||||
}
|
||||
|
||||
async function upload(file: File) {
|
||||
await run("upload", () => api.dbBackups.upload(file), (r) => `Kept ${r.snapshot.name}. It can be restored from the list.`);
|
||||
if (fileRef.current) fileRef.current.value = "";
|
||||
}
|
||||
|
||||
if (!data || !draft) return <div className="card mb-3"><div className="card-body">{error ? <ErrorNotice error={error} /> : <BlockSkeleton lines={4} />}</div></div>;
|
||||
|
||||
const newest = data.snapshots.find((s) => s.kind === "scheduled" || s.kind === "manual");
|
||||
const failing = data.lastAttempt && !data.lastAttempt.ok;
|
||||
const dirty = draft.enabled !== data.settings.enabled || draft.time !== data.settings.time || draft.keep !== data.settings.keep;
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Database backups</h3>
|
||||
<div className="card-actions btn-list">
|
||||
<input ref={fileRef} type="file" accept=".sqlite,.db,application/octet-stream" className="d-none" onChange={(e) => e.target.files?.[0] && void upload(e.target.files[0])} />
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy !== null} onClick={() => fileRef.current?.click()}>
|
||||
{busy === "upload" ? "Uploading…" : "Upload a backup…"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-primary" disabled={busy !== null} onClick={() => void run("create", () => api.dbBackups.create(), (r) => `Backed up: ${r.snapshot.name}`)}>
|
||||
{busy === "create" ? "Backing up…" : "Back up now"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
Everything Homelab Manager knows is in one database file. A copy is taken every day, checked as it is made, and the newest few are kept in <code>{data.folder}</code>.
|
||||
{" "}
|
||||
<strong>A backup does not contain <code>CREDENTIALS_ENCRYPTION_KEY</code></strong> (from <code>.env</code>), which decrypts the credentials stored in it — keep that somewhere else — and it is still on this machine until you copy it away (Download, or copy the folder). The steps are in <code>BACKUP.md</code>.
|
||||
</p>
|
||||
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{failing && (
|
||||
<div className="alert alert-danger">
|
||||
<div>
|
||||
<strong>The last backup didn't work</strong> (<TimeAgo value={data.lastAttempt!.at} />): {data.lastAttempt!.error}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.staged && (
|
||||
<div className="alert alert-warning">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 w-100">
|
||||
<div className="flex-fill">
|
||||
<strong>A restore is waiting.</strong> The database becomes <code>{data.staged.from}</code> the next time Homelab Manager starts — restart it to finish (with the standard Docker setup: <code>docker compose restart homelab-manager</code>). The database in use now is kept as a backup.
|
||||
</div>
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy !== null} onClick={() => void run("cancel", () => api.dbBackups.cancelRestore(), () => "The restore was cancelled.")}>
|
||||
Cancel the restore
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.lastRestore && (
|
||||
<div className="alert alert-success">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 w-100">
|
||||
<div className="flex-fill">
|
||||
<strong>The database was restored</strong> from <code>{data.lastRestore.from}</code> <TimeAgo value={data.lastRestore.restoredAt} />
|
||||
{data.lastRestore.by ? ` (staged by ${data.lastRestore.by})` : ""}.
|
||||
{data.lastRestore.keptAs && (
|
||||
<>
|
||||
{" "}
|
||||
What was in use before is kept as <code>{data.lastRestore.keptAs}</code>.
|
||||
</>
|
||||
)}{" "}
|
||||
Servers whose agents were installed after that backup need their token rotated (Servers → Manage servers).
|
||||
</div>
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => void run("dismiss", () => api.dbBackups.dismissRestoreResult())}>
|
||||
Dismiss
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="row g-3 mb-3">
|
||||
<div className="col-md-4">
|
||||
<div className="text-secondary small">Newest backup</div>
|
||||
<div>{newest ? <><TimeAgo value={newest.at} /> <span className="text-secondary">({size(newest.sizeBytes)})</span></> : <span className="text-warning">none yet</span>}</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<div className="text-secondary small">Next one</div>
|
||||
<div>{data.nextRun ? formatDateTime(new Date(data.nextRun)) : <span className="text-secondary">daily backups are off</span>}</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<div className="text-secondary small">Kept</div>
|
||||
<div>{data.snapshots.length} {data.snapshots.length === 1 ? "file" : "files"}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form
|
||||
className="row g-2 align-items-end mb-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
void run("settings", () => api.dbBackups.saveSettings(draft), () => "Saved.");
|
||||
}}
|
||||
>
|
||||
<div className="col-auto">
|
||||
<label className="form-check form-switch mb-2">
|
||||
<input className="form-check-input" type="checkbox" checked={draft.enabled} onChange={(e) => setDraft({ ...draft, enabled: e.target.checked })} />
|
||||
<span className="form-check-label">Back up every day</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<label className="form-label small mb-1" htmlFor="db-backup-time">
|
||||
At
|
||||
</label>
|
||||
<input id="db-backup-time" type="time" className="form-control form-control-sm" disabled={!draft.enabled} value={draft.time} onChange={(e) => setDraft({ ...draft, time: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<label className="form-label small mb-1" htmlFor="db-backup-keep">
|
||||
Keep the newest
|
||||
</label>
|
||||
<input id="db-backup-keep" type="number" min={1} max={90} className="form-control form-control-sm" style={{ width: 90 }} disabled={!draft.enabled} value={draft.keep} onChange={(e) => setDraft({ ...draft, keep: Number(e.target.value) })} />
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<button type="submit" className="btn btn-sm btn-outline-primary" disabled={!dirty || busy !== null}>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
<div className="col-12 text-secondary small">The time is in the notification time zone (Settings → Notifications). An alert is raised if the newest backup gets more than two days old.</div>
|
||||
</form>
|
||||
|
||||
{data.snapshots.length === 0 ? (
|
||||
<div className="text-secondary">No backups yet. Press Back up now to make the first.</div>
|
||||
) : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-sm table-vcenter mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Backup</th>
|
||||
<th>Kind</th>
|
||||
<th>Taken</th>
|
||||
<th>Size</th>
|
||||
<th className="w-1">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.snapshots.map((s) => (
|
||||
<tr key={s.name}>
|
||||
<td>
|
||||
<code>{s.name}</code>
|
||||
{checks[s.name] && <div className="small mt-1"><CheckResult check={checks[s.name]} /></div>}
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge ${KIND_WORDS[s.kind].badge}`} title={KIND_WORDS[s.kind].hint}>
|
||||
{KIND_WORDS[s.kind].label}
|
||||
</span>
|
||||
</td>
|
||||
<td className="text-nowrap" title={formatDateTime(new Date(s.at))}>
|
||||
<TimeAgo value={s.at} />
|
||||
</td>
|
||||
<td className="text-nowrap">{size(s.sizeBytes)}</td>
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<a className="btn btn-sm btn-outline-secondary" href={api.dbBackups.downloadUrl(s.name)} download>
|
||||
Download
|
||||
</a>
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy !== null} onClick={() => void run(`check:${s.name}`, () => api.dbBackups.check(s.name).then((r) => setChecks((c) => ({ ...c, [s.name]: r.check }))))}>
|
||||
{busy === `check:${s.name}` ? "Checking…" : "Check"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-warning" disabled={busy !== null || data.staged !== null} onClick={() => void restore(s)}>
|
||||
Restore…
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger" disabled={busy !== null} onClick={() => void remove(s)}>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -29,6 +29,7 @@ export default function StatusStrip() {
|
||||
const silenced = report.counts.silenced;
|
||||
const grouped = report.counts.grouped ?? 0;
|
||||
const blind = report.couldntCheck.length;
|
||||
const acked = report.counts.acknowledged ?? 0;
|
||||
|
||||
const notes: string[] = [];
|
||||
if (silenced > 0) notes.push(`${silenced} silenced by maintenance`);
|
||||
@@ -43,13 +44,13 @@ export default function StatusStrip() {
|
||||
<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>{" "}
|
||||
<strong>{unsure ? "No active alerts, but some checks couldn't run." : acked > 0 ? "Nothing new." : "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>
|
||||
<span className="text-secondary">{acked > 0 ? `${acked} acknowledged — somebody is on ${acked === 1 ? "it" : "them"}. See Alerts.` : "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>}
|
||||
@@ -59,9 +60,11 @@ export default function StatusStrip() {
|
||||
);
|
||||
}
|
||||
|
||||
const need = report.counts.attention ?? report.counts;
|
||||
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,
|
||||
need.critical > 0 ? `${need.critical} critical` : null,
|
||||
need.warning > 0 ? `${need.warning} warning${need.warning === 1 ? "" : "s"}` : null,
|
||||
(report.counts.acknowledged ?? 0) > 0 ? `${report.counts.acknowledged} acknowledged` : null,
|
||||
].filter(Boolean);
|
||||
|
||||
return (
|
||||
|
||||
@@ -74,7 +74,9 @@ export function useAlertsReport(): State & { reload: () => void } {
|
||||
/** What the sidebar shows next to Alerts: how many problems are active, coloured by the worst one. Silenced and informational ones don't count. */
|
||||
export function alertBadge(report: AlertsReport | null): { count: number; level: "critical" | "warning" } | null {
|
||||
if (!report) return null;
|
||||
const count = report.counts.critical + report.counts.warning;
|
||||
// What still needs somebody to look: alerts somebody has acknowledged don't count here (they are still on the Alerts page, marked).
|
||||
const c = report.counts.attention ?? report.counts;
|
||||
const count = c.critical + c.warning;
|
||||
if (count === 0) return null;
|
||||
return { count, level: report.counts.critical > 0 ? "critical" : "warning" };
|
||||
return { count, level: c.critical > 0 ? "critical" : "warning" };
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
IconUsers,
|
||||
IconDevices,
|
||||
IconHistory,
|
||||
IconTimeline,
|
||||
IconStethoscope,
|
||||
IconSettings,
|
||||
IconWand,
|
||||
@@ -105,6 +106,7 @@ export const NAV: NavEntry[] = [
|
||||
icon: <IconTool size={20} />,
|
||||
items: [
|
||||
{ to: "/alerts", label: "Alerts", icon: <IconAlertTriangle size={20} /> },
|
||||
{ to: "/incidents", label: "Incidents", icon: <IconTimeline size={20} /> },
|
||||
{ to: "/maintenance", label: "Maintenance", icon: <IconTool size={20} /> },
|
||||
{ to: "/updates", label: "Updates", icon: <IconDownload size={20} /> },
|
||||
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
|
||||
|
||||
@@ -14,6 +14,8 @@ import TableToolbar from "../components/TableToolbar";
|
||||
import SilenceButton from "../components/SilenceButton";
|
||||
import RunPlaybookButton from "../components/RunPlaybookButton";
|
||||
import RunbookEntry from "../components/RunbookEntry";
|
||||
import AckDrawer, { ackWords } from "../components/AckDrawer";
|
||||
import { useAlertsReport } from "../hooks/useAlertsReport";
|
||||
|
||||
const SEVERITY: Record<AlertSeverity, { label: string; badge: string; rank: number }> = {
|
||||
critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 },
|
||||
@@ -38,6 +40,8 @@ type Row = AlertItem & { rank: number };
|
||||
|
||||
export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const canSilence = user.role === "admin" || user.role === "operator";
|
||||
// The count beside Alerts in the menu is a shared one on its own timer; after an acknowledgement it should change at once.
|
||||
const { reload: reloadBadge } = useAlertsReport();
|
||||
const [report, setReport] = useState<AlertsReport | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -45,6 +49,9 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const [category, setCategory] = useState<"all" | AlertCategory>("all");
|
||||
const [search, setSearch] = useState("");
|
||||
const [showSilenced, setShowSilenced] = useState(true);
|
||||
// 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);
|
||||
|
||||
function load(refresh = false) {
|
||||
setLoading(true);
|
||||
@@ -67,9 +74,13 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const q = search.trim().toLowerCase();
|
||||
return report.alerts
|
||||
.filter((a) => (severity === "all" || a.severity === severity) && (category === "all" || a.category === category) && (showSilenced || !a.silenced))
|
||||
.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]);
|
||||
}, [report, severity, category, search, showSilenced, attention, user.id]);
|
||||
|
||||
// No initial sort: the server already puts active problems first, worst first.
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(rows);
|
||||
@@ -80,16 +91,17 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"alerts.csv",
|
||||
["Severity", "Category", "Source", "Alert", "Silenced", "Ticket"],
|
||||
(sorted ?? []).map((a) => [SEVERITY[a.severity].label, CATEGORY_LABELS[a.category], a.source, a.message, a.silenced ? "yes" : "no", a.ticket ? (a.ticket.number ?? "opened") : ""]),
|
||||
["Severity", "Category", "Source", "Alert", "Silenced", "Ticket", "Acknowledged by", "Has it", "Note"],
|
||||
(sorted ?? []).map((a) => [SEVERITY[a.severity].label, CATEGORY_LABELS[a.category], a.source, a.message, a.silenced ? "yes" : "no", a.ticket ? (a.ticket.number ?? "opened") : "", a.ack?.active ? a.ack.ackedBy : "", a.ack?.active ? (a.ack.assignee?.name ?? "") : "", a.ack?.active ? a.ack.note : ""]),
|
||||
);
|
||||
}
|
||||
|
||||
const counts = report?.counts;
|
||||
const nothingFound = report !== null && report.alerts.length === 0;
|
||||
const cards: { label: string; value: number | undefined; color: string }[] = [
|
||||
{ label: "Critical", value: counts?.critical, color: "text-red" },
|
||||
{ label: "Warnings", value: counts?.warning, color: "text-yellow" },
|
||||
{ label: "Critical", value: counts?.attention?.critical ?? counts?.critical, color: "text-red" },
|
||||
{ label: "Warnings", value: counts?.attention?.warning ?? counts?.warning, color: "text-yellow" },
|
||||
...((counts?.acknowledged ?? 0) > 0 ? [{ label: "Acknowledged", value: counts?.acknowledged, color: "text-blue" }] : []),
|
||||
{ label: "Info", value: counts?.info, color: "text-blue" },
|
||||
{ label: "Silenced (maintenance)", value: counts?.silenced, color: "text-secondary" },
|
||||
...((counts?.grouped ?? 0) > 0 ? [{ label: "Grouped under another", value: counts?.grouped, color: "text-secondary" }] : []),
|
||||
@@ -200,6 +212,14 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{(counts?.acknowledged ?? 0) > 0 && (
|
||||
<select className="form-select form-select-sm w-auto" aria-label="Whether somebody is on it" value={attention} onChange={(e) => setAttention(e.target.value as typeof attention)}>
|
||||
<option value="all">Acknowledged or not</option>
|
||||
<option value="unacknowledged">Nobody is on it</option>
|
||||
<option value="acknowledged">Acknowledged</option>
|
||||
<option value="mine">Handed to me</option>
|
||||
</select>
|
||||
)}
|
||||
{(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)} />
|
||||
@@ -245,6 +265,22 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
{a.ack?.active && (
|
||||
<div className="small mt-1">
|
||||
<span className="badge bg-blue-lt text-blue me-1" title={`Acknowledged by ${a.ack.ackedBy}`}>
|
||||
{ackWords(a.ack)}
|
||||
</span>
|
||||
{a.ack.note && <span className="text-secondary">{a.ack.note}</span>}
|
||||
</div>
|
||||
)}
|
||||
{a.ack && !a.ack.active && (
|
||||
<div className="small mt-1 text-secondary">Its acknowledgement ran out — nobody is on it now.</div>
|
||||
)}
|
||||
{a.incidentId != null && (
|
||||
<div className="small">
|
||||
<Link to={`/incidents/${a.incidentId}`}>Timeline</Link>
|
||||
</div>
|
||||
)}
|
||||
{a.target && (
|
||||
<div>
|
||||
<RunbookEntry targetType={a.target.type} targetId={a.target.id} targetName={a.target.name} canEdit={canSilence} forCategory={a.category} />
|
||||
@@ -273,6 +309,11 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
{canSilence && (
|
||||
<td className="text-nowrap">
|
||||
<div className="btn-list flex-nowrap">
|
||||
{!a.silenced && (
|
||||
<button type="button" className={`btn btn-sm ${a.ack?.active ? "btn-outline-primary" : "btn-outline-secondary"}`} onClick={() => setAcking(a)}>
|
||||
{a.ack?.active ? "Acknowledged" : "Acknowledge…"}
|
||||
</button>
|
||||
)}
|
||||
<SilenceButton alert={a} onDone={() => void load(true)} />
|
||||
{a.target?.type === "server" && !a.silenced && <RunPlaybookButton serverName={a.target.name} />}
|
||||
</div>
|
||||
@@ -295,6 +336,11 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{acking && <AckDrawer alert={acking} me={user} onClose={() => setAcking(null)} onSaved={() => {
|
||||
void load(true);
|
||||
reloadBadge();
|
||||
}} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type AlertCategory, type IncidentSummary } from "../api/client";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { usePagination } from "../hooks/usePagination";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import Pagination from "../components/Pagination";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
export const CATEGORY_NAMES: Record<AlertCategory, string> = {
|
||||
offline: "Server down",
|
||||
disk: "Disk & storage",
|
||||
services: "Failing services",
|
||||
backup: "Backups",
|
||||
updates: "Updates",
|
||||
expiry: "Expiry",
|
||||
automation: "Automation",
|
||||
integration: "Integration failing",
|
||||
monitoring: "Monitoring",
|
||||
tickets: "Tickets",
|
||||
};
|
||||
|
||||
/** "35 min", "2.5 h", "3 days". */
|
||||
export function durationWords(ms: number): string {
|
||||
const minutes = Math.round(ms / 60_000);
|
||||
if (minutes < 1) return "under a minute";
|
||||
if (minutes < 90) return `${minutes} min`;
|
||||
const hours = ms / 3600_000;
|
||||
if (hours < 48) return `${Math.round(hours * 10) / 10} h`;
|
||||
return `${Math.round(hours / 24)} days`;
|
||||
}
|
||||
|
||||
export const SEVERITY_BADGE: Record<string, string> = { critical: "bg-red-lt text-red", warning: "bg-yellow-lt text-yellow", info: "bg-blue-lt text-blue" };
|
||||
|
||||
type Row = IncidentSummary & { where: string; openFirst: number };
|
||||
|
||||
/**
|
||||
* Every time something was raised as an alert and later went away: when it began, how long it lasted, how bad it got. Open ones are on top.
|
||||
* Open one for everything that happened around it.
|
||||
*/
|
||||
export default function Incidents() {
|
||||
const [incidents, setIncidents] = useState<IncidentSummary[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState<"all" | "open" | "resolved">("all");
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const load = () =>
|
||||
api.incidents
|
||||
.list()
|
||||
.then((res) => alive && setIncidents(res.incidents))
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
void load();
|
||||
const timer = setInterval(load, 30_000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(timer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const rows: Row[] = useMemo(
|
||||
() => (incidents ?? []).filter((i) => status === "all" || (status === "open" ? i.open : !i.open)).map((i) => ({ ...i, where: i.target?.name ?? i.source, openFirst: i.open ? 0 : 1 })),
|
||||
[incidents, status],
|
||||
);
|
||||
const tableSearch = useTableSearch(rows);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "openedAt", "desc", { url: true });
|
||||
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
|
||||
|
||||
const open = (incidents ?? []).filter((i) => i.open).length;
|
||||
const week = (incidents ?? []).filter((i) => Date.now() - Date.parse(i.openedAt) < 7 * 86_400_000).length;
|
||||
const longest = (incidents ?? []).filter((i) => !i.open).sort((a, b) => b.durationMs - a.durationMs)[0];
|
||||
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"incidents.csv",
|
||||
["Began", "Ended", "Lasted (minutes)", "Worst", "Kind", "Where", "What", "Notes"],
|
||||
(sorted ?? []).map((i) => [i.openedAt, i.resolvedAt ?? "", Math.round(i.durationMs / 60_000), i.peakSeverity, CATEGORY_NAMES[i.category] ?? i.category, i.where, i.message, i.notes]),
|
||||
);
|
||||
}
|
||||
|
||||
const cards: { label: string; value: string | number; note?: string; color: string }[] = [
|
||||
{ label: "Open now", value: incidents ? open : "…", color: open > 0 ? "text-red" : "text-green" },
|
||||
{ label: "Began in the last week", value: incidents ? week : "…", color: "" },
|
||||
{ label: "Longest so far", value: longest ? durationWords(longest.durationMs) : incidents ? "—" : "…", note: longest?.message, color: "text-secondary" },
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-1">
|
||||
<h2 className="page-title mb-0">Incidents</h2>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
Each time an alert was raised and later went away is one incident, kept with when it began and ended. Open one to see everything the app knows about that time — who acknowledged it, the maintenance windows, what was changed, the update runs and the notes people wrote.
|
||||
They are recorded from the <Link to="/alerts">Alerts</Link> every few minutes, so one that comes and goes between two looks may not be here.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-lg-4" key={c.label}>
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className={`h2 mb-0 ${c.color}`}>{c.value}</div>
|
||||
<div className="text-secondary">{c.label}</div>
|
||||
{c.note && <div className="text-secondary small text-truncate">{c.note}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<TableToolbar
|
||||
search={tableSearch.query}
|
||||
onSearch={tableSearch.setQuery}
|
||||
placeholder="Search incidents…"
|
||||
filters={
|
||||
<select className="form-select form-select-sm w-auto" aria-label="Show" value={status} onChange={(e) => setStatus(e.target.value as typeof status)}>
|
||||
<option value="all">Open and resolved</option>
|
||||
<option value="open">Open</option>
|
||||
<option value="resolved">Resolved</option>
|
||||
</select>
|
||||
}
|
||||
shown={sorted?.length}
|
||||
total={rows.length}
|
||||
onExport={exportCsv}
|
||||
exportDisabled={!sorted || sorted.length === 0}
|
||||
/>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<SortableTh<Row> label="Began" sortKeyName="openedAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="State" sortKeyName="openFirst" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Lasted" sortKeyName="durationMs" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Worst" sortKeyName="peakSeverity" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Kind" sortKeyName="category" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Where" sortKeyName="where" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="What" sortKeyName="message" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{incidents === null && !error && (
|
||||
<tr>
|
||||
<td colSpan={7}>
|
||||
<BlockSkeleton lines={4} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{(pageItems ?? []).map((i) => (
|
||||
<tr key={i.id}>
|
||||
<td className="text-nowrap">
|
||||
<TimeAgo value={i.openedAt} />
|
||||
</td>
|
||||
<td>{i.open ? <span className="badge bg-red-lt text-red">open</span> : <span className="badge bg-green-lt text-green">resolved</span>}</td>
|
||||
<td className="text-nowrap">{durationWords(i.durationMs)}</td>
|
||||
<td>
|
||||
<span className={`badge ${SEVERITY_BADGE[i.peakSeverity] ?? ""}`}>{i.peakSeverity}</span>
|
||||
</td>
|
||||
<td>{CATEGORY_NAMES[i.category] ?? i.category}</td>
|
||||
<td>{i.target && i.target.type === "server" ? <Link to={`/servers/${i.target.id}`}>{i.where}</Link> : i.where}</td>
|
||||
<td>
|
||||
<Link to={`/incidents/${i.id}`}>{i.message}</Link>
|
||||
{i.causedBy && <span className="badge bg-secondary-lt text-secondary ms-2">caused by {i.causedBy}</span>}
|
||||
{i.notes > 0 && (
|
||||
<span className="text-secondary small ms-2">
|
||||
{i.notes} {i.notes === 1 ? "note" : "notes"}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{incidents !== null && (sorted ?? []).length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={7} className="text-secondary text-center">
|
||||
{tableSearch.active || status !== "all" ? "Nothing matches that." : "No incidents yet. They are recorded from the Alerts, so the first one appears when something is raised."}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Pagination page={page} pageCount={pageCount} totalCount={totalCount} onPageChange={setPage} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { useRef, useState } from "react";
|
||||
import { api, type EncryptedExportFile, type ImportResult } from "../../api/client";
|
||||
import { confirmDialog } from "../../utils/dialogs";
|
||||
import { ErrorNotice } from "../../components/Notice";
|
||||
import DatabaseBackups from "../../components/DatabaseBackups";
|
||||
|
||||
function downloadJson(filename: string, data: unknown) {
|
||||
const blob = new Blob([JSON.stringify(data)], { type: "application/json" });
|
||||
@@ -89,6 +90,9 @@ export default function BackupSettings() {
|
||||
<>
|
||||
<h3 className="mb-3">Backup</h3>
|
||||
|
||||
<DatabaseBackups />
|
||||
|
||||
<h4 className="mb-3">Move your configuration</h4>
|
||||
<div className="row row-cards">
|
||||
<div className="col-md-6">
|
||||
<div className="card h-100">
|
||||
|
||||
Reference in new issue
Block a user