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:
bobbanandClaude Sonnet 5.5 committed 2026-10-18 02:21:08 +02:00
1 parent 7a5b623444
commit 2744a84719
41 files changed
+6573 -26

No files matched your search

+139 -1
View File
@@ -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"),