Stale-backup alerts, per-server alert limits, and update runs from the Updates page
- Backups: a guest whose newest backup is older than its limit is an alert (backup kind), in the daily backup message, the digest and /metrics (homelab_backup_guests, ..._last_age_seconds) - Per-server thresholds (servers.thresholds, migration 0030): offline minutes, disk percent, forecast window, backup age, and per-disk limits or "leave alone"; applied everywhere the global ones were; saving clears the alerts cache - Update runs (update_runs, migration 0031): Update... on the Updates page puts the server under maintenance, runs a Semaphore playbook limited to it, waits for the host to report, and reports what is left and whether a restart is due; poller survives restarts - Notification toggle for update-run results; tests and docs Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5dc6cea69c
commit
7a5b623444
42 files changed
+7561
-57
No files matched your search
@@ -0,0 +1,157 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type IntegrationSummary, type SemaphoreTemplate, type UpdatesServer } from "../api/client";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import DetailDrawer from "./DetailDrawer";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import UpdatesBadge from "./UpdatesBadge";
|
||||
|
||||
interface Loaded {
|
||||
integration: IntegrationSummary;
|
||||
templates: SemaphoreTemplate[];
|
||||
}
|
||||
|
||||
const WINDOWS = [
|
||||
{ minutes: 45, label: "45 minutes" },
|
||||
{ minutes: 90, label: "1½ hours" },
|
||||
{ minutes: 180, label: "3 hours" },
|
||||
{ minutes: 360, label: "6 hours" },
|
||||
];
|
||||
|
||||
const LAST_KEY = "hlm.updateRun.template";
|
||||
const remembered = () => {
|
||||
try {
|
||||
return localStorage.getItem(LAST_KEY) ?? "";
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* "Update this server now": pick the playbook that applies updates, and Homelab Manager puts the server under maintenance, runs it for this
|
||||
* server only, follows it, waits for the server to report again and says what is left and whether a restart is due. It asks before it
|
||||
* starts, and says what it will do.
|
||||
*/
|
||||
export default function UpdateRunDrawer({ server, onClose, onStarted }: { server: UpdatesServer; onClose: () => void; onStarted: () => void }) {
|
||||
const [loaded, setLoaded] = useState<Loaded[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [choice, setChoice] = useState(remembered);
|
||||
const [limit, setLimit] = useState(server.name);
|
||||
const [minutes, setMinutes] = useState(90);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.integrations
|
||||
.list()
|
||||
.then(async (res) => {
|
||||
const sems = res.integrations.filter((i) => i.type === "semaphore" && i.enabled);
|
||||
const all = await Promise.all(sems.map((integration) => api.integrations.semaphore.templates(integration.id).then((r): Loaded => ({ integration, templates: r.templates })).catch((): Loaded => ({ integration, templates: [] }))));
|
||||
if (alive) setLoaded(all);
|
||||
})
|
||||
.catch(() => alive && setFailed(true));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const options = (loaded ?? []).flatMap((l) =>
|
||||
l.templates.map((t) => ({ key: `${l.integration.id}:${t.projectId}:${t.id}`, integration: l.integration, template: t, label: `${t.name} — ${t.projectName}${(loaded ?? []).length > 1 ? ` (${l.integration.name})` : ""}` })),
|
||||
);
|
||||
const picked = options.find((o) => o.key === choice);
|
||||
const count = server.updates?.count ?? null;
|
||||
|
||||
async function start() {
|
||||
if (!picked) return;
|
||||
const ok = await confirmDialog({
|
||||
title: `Update ${server.name} now?`,
|
||||
message: `This silences alerts for ${server.name} for up to ${WINDOWS.find((w) => w.minutes === minutes)?.label ?? `${minutes} minutes`}, runs "${picked.template.name}" in ${picked.integration.name} limited to ${limit.trim()}, and waits for the server to report again. The playbook may restart it.`,
|
||||
confirmLabel: "Start the update",
|
||||
});
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.updateRuns.start({ serverId: server.id, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, limit: limit.trim(), windowMinutes: minutes });
|
||||
try {
|
||||
localStorage.setItem(LAST_KEY, picked.key);
|
||||
} catch {
|
||||
// a remembered choice is only a convenience
|
||||
}
|
||||
toast.success(`Started updating ${server.name}.`);
|
||||
onStarted();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<DetailDrawer title={`Update ${server.name}`} subtitle={server.osType === "windows" ? "Windows" : "Linux"} onClose={onClose}>
|
||||
<div className="mb-3">
|
||||
<UpdatesBadge updates={server.updates} />
|
||||
{count !== null && count > 0 && server.updates && server.updates.security !== null && <span className="text-secondary small ms-2">{server.updates.security} of them security</span>}
|
||||
</div>
|
||||
|
||||
{failed ? (
|
||||
<div className="text-secondary">Couldn't load the integrations.</div>
|
||||
) : loaded === null ? (
|
||||
<BlockSkeleton lines={3} />
|
||||
) : loaded.length === 0 ? (
|
||||
<div className="text-secondary">
|
||||
There is no Semaphore connected. Add one under <Link to="/integrations">Integrations</Link>, with a playbook that applies updates, and this server can be updated from here.
|
||||
</div>
|
||||
) : options.length === 0 ? (
|
||||
<div className="text-secondary">No templates found in Semaphore.</div>
|
||||
) : (
|
||||
<>
|
||||
<ol className="text-secondary small ps-3 mb-3">
|
||||
<li>Alerts for this server are silenced (a maintenance window).</li>
|
||||
<li>The playbook runs in Semaphore, for this server only.</li>
|
||||
<li>Homelab Manager waits for the server to report again — it may be restarting.</li>
|
||||
<li>It tells you what is still waiting and whether a restart is due, and the window ends.</li>
|
||||
</ol>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-template">
|
||||
Playbook that applies updates
|
||||
</label>
|
||||
<select id="ur-template" className="form-select" value={choice} onChange={(e) => setChoice(e.target.value)}>
|
||||
<option value="">Choose a template…</option>
|
||||
{options.map((o) => (
|
||||
<option key={o.key} value={o.key}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-limit">
|
||||
Run it on — the host name as it is in the Semaphore inventory
|
||||
</label>
|
||||
<input id="ur-limit" className="form-control" value={limit} maxLength={200} onChange={(e) => setLimit(e.target.value)} placeholder="e.g. web01" />
|
||||
<div className="form-hint text-secondary small mt-1">An update run is always for this one server, never the whole inventory.</div>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="ur-window">
|
||||
Silence its alerts for up to
|
||||
</label>
|
||||
<select id="ur-window" className="form-select" value={minutes} onChange={(e) => setMinutes(Number(e.target.value))}>
|
||||
{WINDOWS.map((w) => (
|
||||
<option key={w.minutes} value={w.minutes}>
|
||||
{w.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">The window ends sooner, as soon as the run does.</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary" disabled={!picked || busy || limit.trim() === ""} onClick={() => void start()}>
|
||||
{busy ? "Starting…" : "Update now"}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</DetailDrawer>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user