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:
1 parent
c36e2092c5
commit
c17e9aa140
55 files changed
+7177
-27
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { useState } from "react";
|
||||
import { IconBook } from "@tabler/icons-react";
|
||||
import type { AlertCategory, MaintenanceTargetType } from "../api/client";
|
||||
import { useRunbookSummary } from "../hooks/useRunbooks";
|
||||
import DetailDrawer from "./DetailDrawer";
|
||||
import RunbookPanel from "./RunbookPanel";
|
||||
|
||||
/**
|
||||
* A small "Runbook" link that opens what is written down about a server, integration or DNS provider in a side panel. Shown where there is
|
||||
* something to read — for an alert, only if a note fits that kind of alert — and, for those who can write them, where there isn't yet.
|
||||
*/
|
||||
export default function RunbookEntry({
|
||||
targetType,
|
||||
targetId,
|
||||
targetName,
|
||||
canEdit,
|
||||
forCategory,
|
||||
offerAdd = false,
|
||||
}: {
|
||||
targetType: MaintenanceTargetType;
|
||||
targetId: number;
|
||||
targetName: string;
|
||||
canEdit: boolean;
|
||||
forCategory?: AlertCategory;
|
||||
/** Show "Add a runbook" for those who can, when there is none. */
|
||||
offerAdd?: boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const summary = useRunbookSummary();
|
||||
const here = (summary ?? []).filter((r) => r.targetType === targetType && r.targetId === targetId);
|
||||
const fitting = forCategory ? here.filter((r) => r.category === null || r.category === forCategory) : here;
|
||||
if (fitting.length === 0 && !(offerAdd && canEdit && summary !== null)) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-link btn-sm p-0 d-inline-flex align-items-center gap-1 align-baseline"
|
||||
title={fitting.length > 0 ? fitting.map((r) => r.title).join(", ") : `Write down what to do about ${targetName}`}
|
||||
onClick={() => setOpen(true)}
|
||||
>
|
||||
<IconBook size={14} aria-hidden="true" />
|
||||
{fitting.length > 0 ? (fitting.length === 1 ? "Runbook" : `Runbooks (${fitting.length})`) : "Add a runbook"}
|
||||
</button>
|
||||
{open && (
|
||||
<DetailDrawer title="Runbook" subtitle={targetName} onClose={() => setOpen(false)}>
|
||||
<RunbookPanel targetType={targetType} targetId={targetId} targetName={targetName} canEdit={canEdit} forCategory={forCategory} />
|
||||
</DetailDrawer>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type AlertCategory, type MaintenanceTargetType, type Runbook } from "../api/client";
|
||||
import { RUNBOOKS_CHANGED } from "../hooks/useRunbooks";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import RunbookText from "./RunbookText";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
|
||||
export const CATEGORY_WORDS: Record<AlertCategory, string> = {
|
||||
offline: "a server that stopped reporting",
|
||||
disk: "a disk filling up",
|
||||
backup: "a backup problem",
|
||||
updates: "updates waiting",
|
||||
expiry: "something expiring",
|
||||
automation: "a failed automation run",
|
||||
integration: "an integration failing",
|
||||
monitoring: "a monitoring problem",
|
||||
tickets: "tickets",
|
||||
};
|
||||
|
||||
interface Draft {
|
||||
id: number | null;
|
||||
title: string;
|
||||
body: string;
|
||||
category: AlertCategory | "";
|
||||
}
|
||||
|
||||
/**
|
||||
* What to do when something is wrong with this server, integration or DNS provider, written down where whoever is on call will look:
|
||||
* on its page and next to its alerts. Everyone signed in reads them; operators write them. A note can be for one kind of alert (a disk
|
||||
* filling) or for anything about the thing, and when opened from an alert the notes that fit it come first.
|
||||
*/
|
||||
export default function RunbookPanel({
|
||||
targetType,
|
||||
targetId,
|
||||
targetName,
|
||||
canEdit,
|
||||
forCategory,
|
||||
}: {
|
||||
targetType: MaintenanceTargetType;
|
||||
targetId: number;
|
||||
targetName: string;
|
||||
canEdit: boolean;
|
||||
/** Opened from an alert of this kind: the notes that fit it are listed first and marked. */
|
||||
forCategory?: AlertCategory;
|
||||
}) {
|
||||
const [notes, setNotes] = useState<Runbook[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [draft, setDraft] = useState<Draft | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function load() {
|
||||
api.runbooks
|
||||
.list(targetType, targetId)
|
||||
.then((res) => setNotes(res.runbooks))
|
||||
.catch(() => setFailed(true));
|
||||
}
|
||||
useEffect(load, [targetType, targetId]);
|
||||
|
||||
const fits = (n: Runbook) => !forCategory || n.category === null || n.category === forCategory;
|
||||
const ordered = [...(notes ?? [])].sort((a, b) => Number(fits(b)) - Number(fits(a)) || a.title.localeCompare(b.title));
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!draft) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const data = { title: draft.title.trim(), body: draft.body, category: draft.category === "" ? null : draft.category };
|
||||
if (draft.id === null) await api.runbooks.create({ targetType, targetId, ...data });
|
||||
else await api.runbooks.update(draft.id, data);
|
||||
toast.success("Saved.");
|
||||
setDraft(null);
|
||||
load();
|
||||
window.dispatchEvent(new Event(RUNBOOKS_CHANGED));
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(n: Runbook) {
|
||||
if (!(await confirmDialog({ title: "Remove runbook", message: `Remove "${n.title}"?`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.runbooks.remove(n.id);
|
||||
load();
|
||||
window.dispatchEvent(new Event(RUNBOOKS_CHANGED));
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) return <div className="text-secondary">Couldn't load the runbooks.</div>;
|
||||
if (notes === null) return <BlockSkeleton lines={3} />;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ordered.length === 0 && !draft && (
|
||||
<div className="text-secondary mb-3">
|
||||
Nothing written down for {targetName} yet.{canEdit ? " Add what to check first, who to call, how to bring it back." : ""}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{ordered.map((n) => (
|
||||
<div key={n.id} className={`border rounded p-3 mb-3 ${fits(n) ? "" : "opacity-75"}`}>
|
||||
<div className="d-flex flex-wrap align-items-start gap-2 mb-2">
|
||||
<div className="fw-bold me-auto">{n.title}</div>
|
||||
{n.category ? (
|
||||
<span className={`badge ${forCategory && n.category === forCategory ? "bg-blue-lt text-blue" : "bg-secondary-lt text-secondary"}`}>for {CATEGORY_WORDS[n.category as AlertCategory] ?? n.category}</span>
|
||||
) : (
|
||||
<span className="badge bg-secondary-lt text-secondary">for anything about it</span>
|
||||
)}
|
||||
</div>
|
||||
<RunbookText text={n.body} />
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mt-2">
|
||||
<span className="text-secondary small">
|
||||
{n.updatedBy ? `${n.updatedBy}, ` : ""}
|
||||
<TimeAgo value={n.updatedAt} />
|
||||
</span>
|
||||
{canEdit && (
|
||||
<span className="ms-auto btn-list flex-nowrap">
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => setDraft({ id: n.id, title: n.title, body: n.body, category: (n.category as AlertCategory | null) ?? "" })}>
|
||||
Edit
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger" onClick={() => void remove(n)}>
|
||||
Remove
|
||||
</button>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{draft ? (
|
||||
<form onSubmit={save} className="border rounded p-3">
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="rb-title">
|
||||
Title
|
||||
</label>
|
||||
<input id="rb-title" className="form-control" required maxLength={120} placeholder={`e.g. If ${targetName} is down`} value={draft.title} onChange={(e) => setDraft({ ...draft, title: e.target.value })} />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="rb-for">
|
||||
For
|
||||
</label>
|
||||
<select id="rb-for" className="form-select" value={draft.category} onChange={(e) => setDraft({ ...draft, category: e.target.value as AlertCategory | "" })}>
|
||||
<option value="">Anything about it</option>
|
||||
{(Object.keys(CATEGORY_WORDS) as AlertCategory[]).map((c) => (
|
||||
<option key={c} value={c}>
|
||||
Only {CATEGORY_WORDS[c]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="mb-2">
|
||||
<label className="form-label" htmlFor="rb-body">
|
||||
What to do
|
||||
</label>
|
||||
<textarea id="rb-body" className="form-control" rows={9} required maxLength={20000} value={draft.body} onChange={(e) => setDraft({ ...draft, body: e.target.value })} />
|
||||
<div className="form-hint">
|
||||
Plain text. A blank line starts a new paragraph; <code>- </code> makes a list; <code>```</code> around lines makes a block of commands; <code>`like this`</code> is inline code; links are made clickable.
|
||||
</div>
|
||||
</div>
|
||||
{error && <div className="text-danger small mb-2">{error}</div>}
|
||||
<div className="btn-list">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || draft.title.trim() === ""}>
|
||||
{busy ? "Saving…" : "Save"}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
) : (
|
||||
canEdit && (
|
||||
<button type="button" className="btn btn-outline-secondary" onClick={() => setDraft({ id: null, title: "", body: "", category: forCategory ?? "" })}>
|
||||
Add a runbook
|
||||
</button>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import { Fragment, type ReactNode } from "react";
|
||||
|
||||
/**
|
||||
* A runbook's text, drawn. A little formatting, written the way people already write notes — and never raw HTML: everything is built
|
||||
* as plain elements, so nothing typed into a note can run or restyle the page, and a link only becomes a link if it is http or https.
|
||||
*
|
||||
* blank line new paragraph - item / * item a list
|
||||
* 1. item a numbered list # Heading a small heading
|
||||
* ``` … ``` a block of commands \`code\` inline code
|
||||
* **bold** bold https://… a link, as is
|
||||
* [words](https://…) a link with words
|
||||
*/
|
||||
|
||||
const INLINE = /(`[^`\n]+`|\*\*[^*\n]+\*\*|\[[^\]\n]+\]\(https?:\/\/[^\s)]+\)|https?:\/\/[^\s<>"')]+)/g;
|
||||
|
||||
function inline(text: string, keyBase: string): ReactNode[] {
|
||||
return text.split(INLINE).map((part, i) => {
|
||||
const key = `${keyBase}-${i}`;
|
||||
if (!part) return null;
|
||||
if (part.startsWith("`") && part.endsWith("`") && part.length > 2) return <code key={key}>{part.slice(1, -1)}</code>;
|
||||
if (part.startsWith("**") && part.endsWith("**") && part.length > 4) return <strong key={key}>{part.slice(2, -2)}</strong>;
|
||||
const named = /^\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)$/.exec(part);
|
||||
if (named) {
|
||||
return (
|
||||
<a key={key} href={named[2]} target="_blank" rel="noopener noreferrer">
|
||||
{named[1]}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
if (/^https?:\/\//.test(part)) {
|
||||
return (
|
||||
<a key={key} href={part} target="_blank" rel="noopener noreferrer">
|
||||
{part}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
return <Fragment key={key}>{part}</Fragment>;
|
||||
});
|
||||
}
|
||||
|
||||
interface Block {
|
||||
kind: "p" | "ul" | "ol" | "h" | "code";
|
||||
lines: string[];
|
||||
}
|
||||
|
||||
function parse(text: string): Block[] {
|
||||
const blocks: Block[] = [];
|
||||
const lines = text.replace(/\r\n/g, "\n").split("\n");
|
||||
let current: Block | null = null;
|
||||
const flush = () => {
|
||||
if (current) blocks.push(current);
|
||||
current = null;
|
||||
};
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (line.trimStart().startsWith("```")) {
|
||||
flush();
|
||||
const code: string[] = [];
|
||||
for (i++; i < lines.length && !lines[i].trimStart().startsWith("```"); i++) code.push(lines[i]);
|
||||
blocks.push({ kind: "code", lines: code });
|
||||
continue;
|
||||
}
|
||||
if (line.trim() === "") {
|
||||
flush();
|
||||
continue;
|
||||
}
|
||||
const heading = /^#{1,3}\s+(.*)$/.exec(line);
|
||||
if (heading) {
|
||||
flush();
|
||||
blocks.push({ kind: "h", lines: [heading[1]] });
|
||||
continue;
|
||||
}
|
||||
const bullet = /^\s*[-*]\s+(.*)$/.exec(line);
|
||||
const numbered = /^\s*\d+[.)]\s+(.*)$/.exec(line);
|
||||
const kind = bullet ? "ul" : numbered ? "ol" : "p";
|
||||
const content = bullet ? bullet[1] : numbered ? numbered[1] : line;
|
||||
if (current && (current as Block).kind === kind) (current as Block).lines.push(content);
|
||||
else {
|
||||
flush();
|
||||
current = { kind, lines: [content] };
|
||||
}
|
||||
}
|
||||
flush();
|
||||
return blocks;
|
||||
}
|
||||
|
||||
export default function RunbookText({ text }: { text: string }) {
|
||||
const blocks = parse(text);
|
||||
return (
|
||||
<div className="runbook-text">
|
||||
{blocks.map((b, i) => {
|
||||
const key = `b${i}`;
|
||||
if (b.kind === "code") {
|
||||
return (
|
||||
<pre key={key} className="border rounded p-2 mb-2">
|
||||
{b.lines.join("\n")}
|
||||
</pre>
|
||||
);
|
||||
}
|
||||
if (b.kind === "h") return <h5 key={key}>{inline(b.lines[0], key)}</h5>;
|
||||
if (b.kind === "ul" || b.kind === "ol") {
|
||||
const Tag = b.kind;
|
||||
return (
|
||||
<Tag key={key} className="mb-2">
|
||||
{b.lines.map((l, j) => (
|
||||
<li key={j}>{inline(l, `${key}-${j}`)}</li>
|
||||
))}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<p key={key} className="mb-2">
|
||||
{b.lines.map((l, j) => (
|
||||
<Fragment key={j}>
|
||||
{j > 0 && <br />}
|
||||
{inline(l, `${key}-${j}`)}
|
||||
</Fragment>
|
||||
))}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user