Endpoint checks, restore tests, and a change log
- Endpoints: HTTP, TCP and TLS checks with answer time, uptime and certificate expiry; failures and expiring certificates become alerts and notifications; linked to a server for maintenance and tags - Restore tests: record when a backup was restored and how it went; failed tests always alert, overdue ones with a limit set; shown on the Backup coverage page - Change log: one filterable timeline made from the audit log and the incident record Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3bc6bbf72
commit
92726568b7
37 files changed
+6918
-21
No files matched your search
@@ -0,0 +1,209 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type ChangeEntry, type ChangeKind } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
const TONE_DOT: Record<ChangeEntry["tone"], string> = { good: "#2fb344", bad: "#e05252", info: "#4299e1", neutral: "#8a94a6" };
|
||||
|
||||
const RANGES: { days: number; label: string }[] = [
|
||||
{ days: 1, label: "Last 24 hours" },
|
||||
{ days: 7, label: "Last 7 days" },
|
||||
{ days: 30, label: "Last 30 days" },
|
||||
{ days: 90, label: "Last 90 days" },
|
||||
{ days: 400, label: "Everything kept" },
|
||||
];
|
||||
|
||||
const PAGE = 100;
|
||||
|
||||
/**
|
||||
* What has changed, in one list: agents updated, settings changed, maintenance started, dependencies edited, alerts raised and cleared — each as a
|
||||
* sentence, newest first, grouped by day. Narrow it to a kind of change, a server, a stretch of time or a word. The Audit Log is the raw table behind it.
|
||||
*/
|
||||
export default function ChangeLog() {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const days = RANGES.some((r) => r.days === Number(params.get("days"))) ? Number(params.get("days")) : 7;
|
||||
const kind = params.get("kind") ?? "";
|
||||
const serverId = /^\d+$/.test(params.get("serverId") ?? "") ? Number(params.get("serverId")) : undefined;
|
||||
const q = params.get("q") ?? "";
|
||||
|
||||
const [text, setText] = useState(q);
|
||||
const [entries, setEntries] = useState<ChangeEntry[] | null>(null);
|
||||
const [more, setMore] = useState(false);
|
||||
const [kinds, setKinds] = useState<{ id: ChangeKind; label: string }[]>([]);
|
||||
const [servers, setServers] = useState<{ id: number; name: string }[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [loadingMore, setLoadingMore] = useState(false);
|
||||
|
||||
const 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 },
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
api.servers
|
||||
.list()
|
||||
.then((res) => setServers(res.servers.map((s) => ({ id: s.id, name: s.name })).sort((a, b) => a.name.localeCompare(b.name))))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
// What is searched for follows what is typed, a moment after it stops.
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => setParam("q", text.trim() || null), 300);
|
||||
return () => clearTimeout(t);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [text]);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setEntries(null);
|
||||
api.changes
|
||||
.list({ days, kind, serverId, q, limit: PAGE })
|
||||
.then((res) => {
|
||||
if (!alive) return;
|
||||
setEntries(res.entries);
|
||||
setMore(res.more);
|
||||
setKinds(res.kinds);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [days, kind, serverId, q]);
|
||||
|
||||
async function older() {
|
||||
if (!entries || entries.length === 0) return;
|
||||
setLoadingMore(true);
|
||||
try {
|
||||
const res = await api.changes.list({ days, kind, serverId, q, limit: PAGE, before: entries[entries.length - 1].at });
|
||||
setEntries([...entries, ...res.entries]);
|
||||
setMore(res.more);
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setLoadingMore(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Grouped by the day it happened (in this browser's time).
|
||||
const days_: { day: string; items: ChangeEntry[] }[] = [];
|
||||
for (const e of entries ?? []) {
|
||||
const day = formatDate(new Date(e.at));
|
||||
const last = days_[days_.length - 1];
|
||||
if (last && last.day === day) last.items.push(e);
|
||||
else days_.push({ day, items: [e] });
|
||||
}
|
||||
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"change-log.csv",
|
||||
["When", "Kind", "What", "Details", "By", "About"],
|
||||
(entries ?? []).map((e) => [e.at, kinds.find((k) => k.id === e.kind)?.label ?? e.kind, e.title, e.detail ?? "", e.actor ?? "", e.target?.name ?? ""]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<h2 className="page-title mb-0">Change log</h2>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv} disabled={!entries || entries.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
What changed and when: agents updated, settings changed, maintenance started and ended, dependencies edited, alerts raised and cleared. The <Link to="/audit-log">Audit Log</Link> is the raw table behind it.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-body d-flex flex-wrap gap-2 align-items-center">
|
||||
<input className="form-control w-auto flex-grow-1" style={{ maxWidth: "22rem" }} type="search" aria-label="Search the change log" placeholder="Search: a server, a person, a word…" value={text} onChange={(e) => setText(e.target.value)} />
|
||||
<select className="form-select w-auto" aria-label="Kind of change" value={kind} onChange={(e) => setParam("kind", e.target.value || null)}>
|
||||
<option value="">All kinds</option>
|
||||
{kinds.map((k) => (
|
||||
<option key={k.id} value={k.id}>
|
||||
{k.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select className="form-select w-auto" aria-label="Server" value={serverId ?? ""} onChange={(e) => setParam("serverId", e.target.value || null)}>
|
||||
<option value="">Every server</option>
|
||||
{servers.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select className="form-select w-auto" aria-label="How far back" value={days} onChange={(e) => setParam("days", e.target.value === "7" ? null : e.target.value)}>
|
||||
{RANGES.map((r) => (
|
||||
<option key={r.days} value={r.days}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{entries === null && !error && <BlockSkeleton lines={5} />}
|
||||
{entries !== null && entries.length === 0 && (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary text-center">
|
||||
Nothing {q || kind || serverId ? "matches that" : "has changed"} in {RANGES.find((r) => r.days === days)?.label.toLowerCase()}.
|
||||
{(q || kind || serverId || days < 400) && " Try a wider range or fewer filters."}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{days_.map((group) => (
|
||||
<div className="card mb-3" key={group.day}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{group.day}</h3>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{group.items.map((e) => (
|
||||
<div className="list-group-item" key={e.id}>
|
||||
<div className="d-flex gap-3">
|
||||
<span className="flex-shrink-0 text-secondary small text-nowrap" style={{ width: "3.2rem" }}>
|
||||
{formatTime(new Date(e.at), false)}
|
||||
</span>
|
||||
<span aria-hidden="true" className="flex-shrink-0 mt-2" style={{ width: 8, height: 8, borderRadius: "50%", background: TONE_DOT[e.tone] }} />
|
||||
<div className="flex-fill" style={{ minWidth: 0 }}>
|
||||
<div className="text-break">
|
||||
{e.title}
|
||||
{e.link && (
|
||||
<Link to={e.link} className="ms-2 small">
|
||||
open
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
{e.detail && <div className="text-secondary small text-break">{e.detail}</div>}
|
||||
<div className="text-secondary small">
|
||||
{kinds.find((k) => k.id === e.kind)?.label ?? e.kind}
|
||||
{e.actor ? ` · ${e.actor}` : ""}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{more && (
|
||||
<div className="text-center mb-3">
|
||||
<button className="btn" onClick={() => void older()} disabled={loadingMore}>
|
||||
{loadingMore ? "Loading…" : "Show older"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user