Add runbooks, backup coverage, inventory, roles from groups, Prometheus metrics and event webhooks

- Runbooks: notes per server/integration, shown next to matching alerts
- Backup coverage page across Proxmox and PBS, with a digest section
- Hardware inventory with warranty, power and running cost
- Authentik group to role mapping with preview and safeguards
- /metrics (bearer token) and signed outgoing event webhooks
- Docs: README, DATABASE, NOTIFICATIONS, ROLES and new API.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-17 20:41:00 +02:00
1 parent c36e2092c5
commit c17e9aa140
55 files changed
+7177 -27

No files matched your search

+238
View File
@@ -0,0 +1,238 @@
import { useEffect, useState } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type BackupCoverage, type CoverageGuest, type CoverageStatus } from "../api/client";
import Pagination from "../components/Pagination";
import SortableTh from "../components/SortableTh";
import TableToolbar from "../components/TableToolbar";
import TimeAgo from "../components/TimeAgo";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import { usePagination } from "../hooks/usePagination";
import { useSortable } from "../hooks/useSortable";
import { useTableSearch } from "../hooks/useTableSearch";
import { downloadCsv } from "../utils/csv";
import { readableError } from "../utils/errors";
interface Row extends CoverageGuest {
/** Worst first, so a default sort puts what needs attention at the top. */
rank: number;
}
const RANK: Record<CoverageStatus, number> = { failed: 0, none: 1, stale: 2, unknown: 3, ok: 4 };
const STATUS: Record<CoverageStatus, { label: string; badge: string; hint: string }> = {
ok: { label: "Recent backup", badge: "bg-green-lt text-green", hint: "Backed up within the limit, and nothing failed." },
stale: { label: "Stale", badge: "bg-yellow-lt text-yellow", hint: "Its newest backup is older than the limit." },
failed: { label: "Failed", badge: "bg-red-lt text-red", hint: "The latest backup didn't succeed, or the newest snapshot failed verification." },
none: { label: "No backup", badge: "bg-red-lt text-red", hint: "No backup found, and no backup job covers it." },
unknown: { label: "Unknown", badge: "bg-secondary-lt text-secondary", hint: "A backup job covers it, but nothing here says when it last ran — typical when backups go somewhere other than a Backup Server." },
};
const STALE_CHOICES = [1, 2, 3, 7, 14];
/**
* What is and isn't backed up: every Proxmox guest, whether a backup job covers it, when it was last backed up (from Proxmox Backup Server
* snapshots and Proxmox's own backup tasks), and whether that went well — one page instead of an alert per gap.
*/
export default function Backups() {
const [params, setParams] = useSearchParams();
const staleParam = Number(params.get("stale"));
const staleDays = STALE_CHOICES.includes(staleParam) ? staleParam : 2;
const statusParam = params.get("status");
const status: CoverageStatus | "attention" | "" = statusParam === "attention" || (statusParam && statusParam in RANK) ? (statusParam as CoverageStatus | "attention") : "";
const [report, setReport] = useState<BackupCoverage | null>(null);
const [error, setError] = useState<string | null>(null);
const [checking, setChecking] = useState(false);
function load(refresh = false) {
setChecking(true);
api.backups
.coverage(staleDays, refresh)
.then((r) => {
setReport(r);
setError(null);
})
.catch((err) => setError(readableError(err)))
.finally(() => setChecking(false));
}
useEffect(() => load(), [staleDays]);
function setParam(key: string, value: string | null) {
setParams(
(prev) => {
const next = new URLSearchParams(prev);
if (value) next.set(key, value);
else next.delete(key);
return next;
},
{ replace: true },
);
}
const rows: Row[] = (report?.guests ?? []).map((g) => ({ ...g, rank: RANK[g.status] }));
const shown = rows.filter((r) => (status === "" ? true : status === "attention" ? r.status === "failed" || r.status === "none" || r.status === "stale" : r.status === status));
const tableSearch = useTableSearch(shown);
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "rank", "asc", { url: true });
const page = usePagination(sorted);
const c = report?.counts;
const trouble = (c?.failed ?? 0) + (c?.none ?? 0) + (c?.stale ?? 0);
const badSources = (report?.sources ?? []).filter((s) => !s.ok);
function exportCsv() {
if (!sorted) return;
downloadCsv(
"backup-coverage.csv",
["Guest", "Type", "ID", "Node", "Cluster", "In a backup job", "Last backup", "Source", "Status", "Problem"],
sorted.map((r) => [r.name, r.type === "qemu" ? "VM" : "Container", r.vmid, r.node, r.integrationName, r.inJob ? "yes" : "no", r.lastBackupAt ?? "", r.lastSource === "pbs" ? "Backup Server" : r.lastSource === "task" ? "Proxmox task" : "", STATUS[r.status].label, r.failure ?? ""]),
);
}
const cards: { label: string; value: string | number; color: string; note?: string }[] = [
{ label: "Guests", value: report ? (c?.total ?? 0) : "…", color: "" },
{ label: "Recent backup", value: report ? (c?.ok ?? 0) : "…", color: "text-green" },
{ label: "Failed", value: report ? (c?.failed ?? 0) : "…", color: (c?.failed ?? 0) > 0 ? "text-red" : "" },
{ label: "No backup", value: report ? (c?.none ?? 0) : "…", color: (c?.none ?? 0) > 0 ? "text-red" : "" },
{ label: "Stale", value: report ? (c?.stale ?? 0) : "…", color: (c?.stale ?? 0) > 0 ? "text-yellow" : "", note: `older than ${staleDays} ${staleDays === 1 ? "day" : "days"}` },
{ label: "Unknown", value: report ? (c?.unknown ?? 0) : "…", color: "text-secondary", note: (c?.unknown ?? 0) > 0 ? "in a job, last run not visible" : undefined },
];
return (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-3">
<h2 className="page-title mb-0">Backup coverage</h2>
<button className="btn btn-outline-secondary ms-auto" onClick={() => load(true)} disabled={checking}>
{checking ? "Checking…" : "Check now"}
</button>
</div>
<p className="text-secondary">
Every Proxmox guest: is a backup job covering it, when was it last backed up, and did that go well. {report && trouble > 0 ? `${trouble} need a look.` : ""}
</p>
<ErrorNotice error={error} />
{badSources.length > 0 && (
<div className="alert alert-warning">
Couldn't read everything — what is missing below isn't necessarily wrong:{" "}
{badSources.map((s) => `${s.kind === "pbs" ? "Backup Server" : "Proxmox"} “${s.name}” (${s.error})`).join("; ")}.
</div>
)}
<div className="row row-cards mb-3">
{cards.map((card) => (
<div className="col-6 col-lg-2" key={card.label}>
<div className="card card-sm">
<div className="card-body">
<div className={`h2 mb-0 ${card.color}`}>{card.value}</div>
<div className="text-secondary">{card.label}</div>
{card.note && <div className="text-secondary small">{card.note}</div>}
</div>
</div>
</div>
))}
</div>
<div className="card">
<TableToolbar
search={tableSearch.query}
onSearch={tableSearch.setQuery}
placeholder="Search guests…"
filters={
<>
<select className="form-select form-select-sm w-auto" aria-label="Show guests that are" value={status} onChange={(e) => setParam("status", e.target.value)}>
<option value="">All guests</option>
<option value="attention">Needing attention</option>
{(Object.keys(RANK) as CoverageStatus[]).map((s) => (
<option key={s} value={s}>
{STATUS[s].label}
</option>
))}
</select>
<select className="form-select form-select-sm w-auto" aria-label="Stale after" value={staleDays} onChange={(e) => setParam("stale", e.target.value === "2" ? null : e.target.value)}>
{STALE_CHOICES.map((d) => (
<option key={d} value={d}>
Stale after {d} {d === 1 ? "day" : "days"}
</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="Guest" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="In a job" sortKeyName="inJob" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="Last backup" sortKeyName="lastBackupAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="Status" sortKeyName="rank" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
</tr>
</thead>
<tbody>
{report === null && !error && (
<tr>
<td colSpan={4}>
<BlockSkeleton lines={4} />
</td>
</tr>
)}
{page.pageItems?.map((r) => (
<tr key={`${r.integrationId}:${r.type}:${r.vmid}`}>
<td>
{r.name}
<div className="text-secondary small">
{r.type === "qemu" ? "VM" : "Container"} {r.vmid} · {r.node}
{report && report.sources.filter((s) => s.kind === "proxmox").length > 1 ? ` · ${r.integrationName}` : ""}
</div>
{r.server && (
<div className="small">
is <Link to={`/servers/${r.server.id}`}>{r.server.name}</Link>
</div>
)}
</td>
<td>{r.inJob ? <span className="text-green">yes</span> : <span className="text-red">no</span>}</td>
<td>
{r.lastBackupAt ? (
<>
<TimeAgo value={r.lastBackupAt} />
<div className="text-secondary small">{r.lastSource === "pbs" ? "Backup Server" : "Proxmox task"}</div>
</>
) : (
<span className="text-secondary">—</span>
)}
</td>
<td>
<span className={`badge ${STATUS[r.status].badge}`} title={STATUS[r.status].hint}>
{STATUS[r.status].label}
</span>
{r.failure && <div className="text-secondary small">{r.failure}</div>}
</td>
</tr>
))}
{report !== null && sorted?.length === 0 && (
<tr>
<td colSpan={4} className="text-secondary text-center">
{rows.length === 0 ? (
<>
No Proxmox guests to show. Connect a Proxmox integration under <Link to="/integrations">Integrations</Link>.
</>
) : (
"Nothing matches that."
)}
</td>
</tr>
)}
</tbody>
</table>
</div>
<Pagination page={page.page} pageCount={page.pageCount} totalCount={page.totalCount} onPageChange={page.setPage} />
<div className="card-footer text-secondary small">
“Last backup” is the newest snapshot of the guest on a Proxmox Backup Server, or the last successful Proxmox backup task that names it. A task from an “all guests” job doesn't
name its guests, so a guest backed up to something other than a Backup Server reads “Unknown” rather than being guessed at. The result is kept for a minute; “Check now” asks again.
</div>
</div>
</>
);
}