Fold alerts under their host, recurring maintenance, run playbooks from alerts, and an Updates page
- Servers can say what they run on (or it is worked out from the Proxmox node); when the host is down the guests' offline alerts fold under it: held back, not counted, not notified, still recorded. - Recurring maintenance schedules made into ordinary windows a week ahead (maintenance_schedules). - Run a Semaphore template limited to a server from its page or an alert, and watch the run. - Agents report pending updates (apt, dnf, zypper, Windows Update); an Updates page lists them. - Migrations 0024 and 0025. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44e393f172
commit
171511c6db
45 files changed
+6772
-44
No files matched your search
@@ -129,7 +129,7 @@ export default function MaintenanceTimeline({ windows, now }: { windows: Mainten
|
||||
return (
|
||||
<span
|
||||
key={w.id}
|
||||
className={`timeline-bar ${running ? "timeline-bar-running" : "timeline-bar-scheduled"} ${w.source ? "timeline-bar-mirrored" : ""}`}
|
||||
className={`timeline-bar ${running ? "timeline-bar-running" : "timeline-bar-scheduled"} ${w.source?.startsWith("kuma:") ? "timeline-bar-mirrored" : ""} ${w.source?.startsWith("schedule:") ? "timeline-bar-recurring" : ""}`}
|
||||
style={bar(from, to)}
|
||||
title={`${row.name}: ${formatDateTime(new Date(from))} – ${formatDateTime(new Date(to))}${w.reason ? ` · ${w.reason}` : ""}`}
|
||||
/>
|
||||
@@ -150,6 +150,9 @@ export default function MaintenanceTimeline({ windows, now }: { windows: Mainten
|
||||
<span>
|
||||
<span className="timeline-key timeline-bar-mirrored" /> From Uptime Kuma
|
||||
</span>
|
||||
<span>
|
||||
<span className="timeline-key timeline-bar-recurring" /> Recurring
|
||||
</span>
|
||||
<span>The same windows are listed in the tables below.</span>
|
||||
{further > 0 && <span>{further} further ahead than this range.</span>}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,309 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, type MaintenanceSchedule, type MaintenanceTargetType, type MaintenanceTargets } from "../api/client";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
|
||||
// Monday first, as a week reads; the numbers are what the server keeps (0 = Sunday).
|
||||
const DAYS: { value: number; short: string }[] = [
|
||||
{ value: 1, short: "Mon" },
|
||||
{ value: 2, short: "Tue" },
|
||||
{ value: 3, short: "Wed" },
|
||||
{ value: 4, short: "Thu" },
|
||||
{ value: 5, short: "Fri" },
|
||||
{ value: 6, short: "Sat" },
|
||||
{ value: 0, short: "Sun" },
|
||||
];
|
||||
|
||||
const LENGTHS: { minutes: number; label: string }[] = [
|
||||
{ minutes: 30, label: "30 minutes" },
|
||||
{ minutes: 60, label: "1 hour" },
|
||||
{ minutes: 120, label: "2 hours" },
|
||||
{ minutes: 180, label: "3 hours" },
|
||||
{ minutes: 240, label: "4 hours" },
|
||||
{ minutes: 360, label: "6 hours" },
|
||||
{ minutes: 480, label: "8 hours" },
|
||||
{ minutes: 720, label: "12 hours" },
|
||||
{ minutes: 1440, label: "24 hours" },
|
||||
];
|
||||
|
||||
function daysWords(days: number[]): string {
|
||||
if (days.length === 7) return "Every day";
|
||||
const set = new Set(days);
|
||||
if ([1, 2, 3, 4, 5].every((d) => set.has(d)) && days.length === 5) return "Weekdays";
|
||||
if (days.length === 2 && set.has(6) && set.has(0)) return "Weekends";
|
||||
return DAYS.filter((d) => set.has(d.value)).map((d) => d.short).join(", ");
|
||||
}
|
||||
|
||||
/** "02:00–04:00", with "(+1 d)" when it runs into the next day. */
|
||||
function timeWords(start: string, minutes: number): string {
|
||||
const [h, m] = start.split(":").map(Number);
|
||||
const end = h * 60 + m + minutes;
|
||||
const clock = (t: number) => `${String(Math.floor((t % 1440) / 60)).padStart(2, "0")}:${String(t % 60).padStart(2, "0")}`;
|
||||
return `${start}–${clock(end)}${end >= 1440 ? ` (+${Math.floor(end / 1440)} d)` : ""}`;
|
||||
}
|
||||
|
||||
function namesWords(names: string[]): string {
|
||||
return names.length <= 3 ? names.join(", ") : `${names.slice(0, 3).join(", ")} and ${names.length - 3} more`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintenance that comes back by itself — "every Sunday 02:00–04:00 on these servers". Each time is made into an ordinary maintenance
|
||||
* window a week ahead, so it shows on the timeline and in Scheduled, silences alerts while it runs, and any single one can be cancelled.
|
||||
*/
|
||||
export default function RecurringMaintenance({ canEdit, targets, onChanged }: { canEdit: boolean; targets: MaintenanceTargets | null; onChanged: () => void }) {
|
||||
const [schedules, setSchedules] = useState<MaintenanceSchedule[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
||||
const [name, setName] = useState("");
|
||||
const [reason, setReason] = useState("");
|
||||
const [days, setDays] = useState<number[]>([0]);
|
||||
const [startTime, setStartTime] = useState("02:00");
|
||||
const [minutes, setMinutes] = useState(120);
|
||||
const [picked, setPicked] = useState<Set<string>>(new Set());
|
||||
|
||||
function load() {
|
||||
api.maintenance.schedules
|
||||
.list()
|
||||
.then((res) => setSchedules(res.schedules))
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(load, []);
|
||||
|
||||
const key = (type: MaintenanceTargetType, id: number) => `${type}:${id}`;
|
||||
const groups: { label: string; type: MaintenanceTargetType; items: { id: number; name: string }[] }[] = [
|
||||
{ label: "Servers", type: "server", items: targets?.servers ?? [] },
|
||||
{ label: "Integrations", type: "integration", items: targets?.integrations ?? [] },
|
||||
{ label: "DNS providers", type: "dns_provider", items: targets?.dnsProviders ?? [] },
|
||||
];
|
||||
|
||||
function toggleGroup(type: MaintenanceTargetType, items: { id: number }[]) {
|
||||
setPicked((prev) => {
|
||||
const next = new Set(prev);
|
||||
const all = items.every((i) => next.has(key(type, i.id)));
|
||||
for (const i of items) (all ? next.delete(key(type, i.id)) : next.add(key(type, i.id)));
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
async function create(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setError(null);
|
||||
setBusy(true);
|
||||
try {
|
||||
const chosen = [...picked].map((k) => {
|
||||
const [type, id] = k.split(":");
|
||||
return { type: type as MaintenanceTargetType, id: Number(id) };
|
||||
});
|
||||
const res = await api.maintenance.schedules.create({ name: name.trim(), reason: reason.trim() || undefined, targets: chosen, days, startTime, durationMinutes: minutes, timezone });
|
||||
toast.success(`Saved. ${res.windowsMade} maintenance window${res.windowsMade === 1 ? "" : "s"} made for the coming week.`);
|
||||
setName("");
|
||||
setReason("");
|
||||
setPicked(new Set());
|
||||
setAdding(false);
|
||||
load();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(s: MaintenanceSchedule) {
|
||||
try {
|
||||
await api.maintenance.schedules.setEnabled(s.id, !s.enabled);
|
||||
load();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(s: MaintenanceSchedule) {
|
||||
if (!(await confirmDialog({ title: "Remove recurring maintenance", message: `Remove "${s.name}"? Windows it made that haven't begun are taken back; one already under way ends on its own.`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.maintenance.schedules.remove(s.id);
|
||||
toast.success(`Removed ${s.name}.`);
|
||||
load();
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
if (schedules !== null && schedules.length === 0 && !canEdit) return null;
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Recurring</h3>
|
||||
{canEdit && !adding && (
|
||||
<div className="card-actions">
|
||||
<button type="button" className="btn btn-sm btn-primary" onClick={() => setAdding(true)}>
|
||||
Add recurring maintenance
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{adding && (
|
||||
<form onSubmit={create}>
|
||||
<div className="card-body row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="rec-name">
|
||||
Name
|
||||
</label>
|
||||
<input id="rec-name" className="form-control" required maxLength={80} placeholder="e.g. Patch night" value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-8">
|
||||
<label className="form-label" htmlFor="rec-reason">
|
||||
Reason (optional)
|
||||
</label>
|
||||
<input id="rec-reason" className="form-control" maxLength={200} placeholder="e.g. OS updates and restarts" value={reason} onChange={(e) => setReason(e.target.value)} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="form-label" id="rec-days">
|
||||
Days
|
||||
</div>
|
||||
<div className="btn-group" role="group" aria-labelledby="rec-days">
|
||||
{DAYS.map((d) => {
|
||||
const on = days.includes(d.value);
|
||||
return (
|
||||
<button key={d.value} type="button" className={`btn btn-sm ${on ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={on} onClick={() => setDays((prev) => (on ? prev.filter((x) => x !== d.value) : [...prev, d.value]))}>
|
||||
{d.short}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-3">
|
||||
<label className="form-label" htmlFor="rec-start">
|
||||
Starts at
|
||||
</label>
|
||||
<input id="rec-start" type="time" className="form-control" required value={startTime} onChange={(e) => setStartTime(e.target.value)} />
|
||||
<div className="form-hint text-secondary small mt-1">Clock in {timezone}</div>
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-3">
|
||||
<label className="form-label" htmlFor="rec-length">
|
||||
For
|
||||
</label>
|
||||
<select id="rec-length" className="form-select" value={minutes} onChange={(e) => setMinutes(Number(e.target.value))}>
|
||||
{LENGTHS.map((l) => (
|
||||
<option key={l.minutes} value={l.minutes}>
|
||||
{l.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<div className="form-label">What it covers</div>
|
||||
<div className="border rounded p-2" style={{ maxHeight: 220, overflowY: "auto" }}>
|
||||
{groups.map(
|
||||
(g) =>
|
||||
g.items.length > 0 && (
|
||||
<fieldset key={g.type} className="mb-2">
|
||||
<legend className="form-label small text-secondary mb-1">
|
||||
{g.label}{" "}
|
||||
<button type="button" className="btn btn-link btn-sm p-0 ms-1" onClick={() => toggleGroup(g.type, g.items)}>
|
||||
{g.items.every((i) => picked.has(key(g.type, i.id))) ? "none" : "all"}
|
||||
</button>
|
||||
</legend>
|
||||
<div className="d-flex flex-wrap gap-3">
|
||||
{g.items.map((i) => (
|
||||
<label key={i.id} className="form-check mb-0">
|
||||
<input
|
||||
type="checkbox"
|
||||
className="form-check-input"
|
||||
checked={picked.has(key(g.type, i.id))}
|
||||
onChange={(e) =>
|
||||
setPicked((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (e.target.checked) next.add(key(g.type, i.id));
|
||||
else next.delete(key(g.type, i.id));
|
||||
return next;
|
||||
})
|
||||
}
|
||||
/>
|
||||
<span className="form-check-label">{i.name}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</fieldset>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<ErrorNotice error={error} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || picked.size === 0 || days.length === 0 || name.trim() === ""}>
|
||||
{busy ? "Saving…" : "Save"}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setAdding(false)}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{!adding && <ErrorNotice error={error} />}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Covers</th>
|
||||
<th>When</th>
|
||||
<th>Next</th>
|
||||
{canEdit && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{schedules?.map((s) => (
|
||||
<tr key={s.id} className={s.enabled ? undefined : "text-secondary"}>
|
||||
<td>
|
||||
{s.name}
|
||||
{!s.enabled && <span className="badge bg-secondary-lt text-secondary ms-2">off</span>}
|
||||
{s.reason && <div className="text-secondary small">{s.reason}</div>}
|
||||
</td>
|
||||
<td>{namesWords(s.targets.map((t) => t.name))}</td>
|
||||
<td>
|
||||
{daysWords(s.days)} {timeWords(s.startTime, s.durationMinutes)}
|
||||
{s.timezone !== timezone && <span className="text-secondary small"> ({s.timezone})</span>}
|
||||
</td>
|
||||
<td>{s.nextStart ? <TimeAgo value={s.nextStart} /> : "—"}</td>
|
||||
{canEdit && (
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => void toggle(s)}>
|
||||
{s.enabled ? "Turn off" : "Turn on"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-sm btn-outline-danger" onClick={() => void remove(s)}>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{schedules?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={canEdit ? 5 : 4} className="text-secondary text-center">
|
||||
Nothing repeats yet. Add one for the night you patch, and its windows appear a week ahead.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type IntegrationSummary, type SemaphoreTask, type SemaphoreTemplate } from "../api/client";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
|
||||
interface Loaded {
|
||||
integration: IntegrationSummary;
|
||||
templates: SemaphoreTemplate[];
|
||||
failed: boolean;
|
||||
}
|
||||
|
||||
const STATUS_WORDS: Record<SemaphoreTask["status"], { label: string; badge: string }> = {
|
||||
waiting: { label: "Waiting to start", badge: "bg-secondary-lt text-secondary" },
|
||||
starting: { label: "Starting", badge: "bg-blue-lt text-blue" },
|
||||
running: { label: "Running", badge: "bg-blue-lt text-blue" },
|
||||
waiting_confirmation: { label: "Waiting for approval in Semaphore", badge: "bg-yellow-lt text-yellow" },
|
||||
confirmed: { label: "Approved", badge: "bg-blue-lt text-blue" },
|
||||
rejected: { label: "Rejected in Semaphore", badge: "bg-red-lt text-red" },
|
||||
stopping: { label: "Stopping", badge: "bg-yellow-lt text-yellow" },
|
||||
stopped: { label: "Stopped", badge: "bg-secondary-lt text-secondary" },
|
||||
success: { label: "Finished — success", badge: "bg-green-lt text-green" },
|
||||
error: { label: "Finished — failed", badge: "bg-red-lt text-red" },
|
||||
};
|
||||
const FINISHED = new Set<SemaphoreTask["status"]>(["success", "error", "stopped", "rejected"]);
|
||||
|
||||
/**
|
||||
* Starts a Semaphore template — optionally on this server only — and shows how the run gets on. It is the same "run" the Semaphore page
|
||||
* has, with the one addition that matters from a server or an alert: ansible's limit, so "apply updates" touches the one machine and
|
||||
* not the whole inventory. Asks first, and says plainly when there is no limit.
|
||||
*/
|
||||
export default function RunPlaybook({ serverName, defaultLimit }: { serverName: string; defaultLimit: string }) {
|
||||
const [loaded, setLoaded] = useState<Loaded[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [choice, setChoice] = useState("");
|
||||
const [limitOn, setLimitOn] = useState(true);
|
||||
const [limit, setLimit] = useState(defaultLimit);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [run, setRun] = useState<{ integrationId: number; projectId: number; name: string; limit: string; task: SemaphoreTask } | null>(null);
|
||||
const alive = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
alive.current = true;
|
||||
api.integrations
|
||||
.list()
|
||||
.then(async (res) => {
|
||||
const servers = res.integrations.filter((i) => i.type === "semaphore" && i.enabled);
|
||||
const all = await Promise.all(
|
||||
servers.map((integration) =>
|
||||
api.integrations.semaphore
|
||||
.templates(integration.id)
|
||||
.then((r): Loaded => ({ integration, templates: r.templates, failed: false }))
|
||||
.catch((): Loaded => ({ integration, templates: [], failed: true })),
|
||||
),
|
||||
);
|
||||
if (alive.current) setLoaded(all);
|
||||
})
|
||||
.catch(() => alive.current && setFailed(true));
|
||||
return () => {
|
||||
alive.current = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Watch a run until it is over.
|
||||
useEffect(() => {
|
||||
if (!run || FINISHED.has(run.task.status)) return;
|
||||
const timer = setInterval(() => {
|
||||
api.integrations.semaphore
|
||||
.task(run.integrationId, run.projectId, run.task.id)
|
||||
.then((res) => alive.current && setRun((r) => (r && r.task.id === res.task.id ? { ...r, task: res.task } : r)))
|
||||
.catch(() => {
|
||||
// Keep asking: one missed answer isn't the end of the run.
|
||||
});
|
||||
}, 3000);
|
||||
return () => clearInterval(timer);
|
||||
}, [run?.task.id, run?.task.status, run?.integrationId, run?.projectId]);
|
||||
|
||||
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 limitText = limitOn ? limit.trim() : "";
|
||||
|
||||
async function start() {
|
||||
if (!picked) return;
|
||||
const where = limitText ? `on ${limitText} only` : "on everything the playbook covers — it isn't limited to one server";
|
||||
if (
|
||||
!(await confirmDialog({
|
||||
title: `Run ${picked.template.name}?`,
|
||||
message: `This starts "${picked.template.name}" in ${picked.integration.name} ${where}.`,
|
||||
confirmLabel: "Run it",
|
||||
danger: !limitText,
|
||||
}))
|
||||
)
|
||||
return;
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await api.integrations.semaphore.run(picked.integration.id, picked.template.projectId, picked.template.id, limitText ? { limit: limitText } : undefined);
|
||||
setRun({ integrationId: picked.integration.id, projectId: picked.template.projectId, name: picked.template.name, limit: limitText, task: res.task });
|
||||
toast.success(`Started ${picked.template.name}${limitText ? ` on ${limitText}` : ""}.`);
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) return <div className="text-secondary">Couldn't load the integrations.</div>;
|
||||
if (loaded === null) return <BlockSkeleton lines={3} />;
|
||||
if (loaded.length === 0) {
|
||||
return (
|
||||
<div className="text-secondary">
|
||||
There is no Semaphore connected. Add one under <Link to="/integrations">Integrations</Link> to run playbooks from here.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{loaded.some((l) => l.failed) && <div className="text-secondary small mb-2">Couldn't read the templates of {loaded.filter((l) => l.failed).map((l) => l.integration.name).join(", ")}.</div>}
|
||||
{options.length === 0 ? (
|
||||
<div className="text-secondary">No templates found in Semaphore.</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="mb-3">
|
||||
<label className="form-label" htmlFor="run-template">
|
||||
Template
|
||||
</label>
|
||||
<select id="run-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>
|
||||
{picked?.template.lastTask && (
|
||||
<div className="form-hint text-secondary small mt-1">
|
||||
Last run here: {picked.template.lastTask.status}
|
||||
{picked.template.lastTask.end ? (
|
||||
<>
|
||||
, <TimeAgo value={picked.template.lastTask.end} />
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-check">
|
||||
<input type="checkbox" className="form-check-input" checked={limitOn} onChange={(e) => setLimitOn(e.target.checked)} />
|
||||
<span className="form-check-label">Run on {serverName} only</span>
|
||||
</label>
|
||||
{limitOn ? (
|
||||
<div className="mt-2">
|
||||
<label className="form-label small" htmlFor="run-limit">
|
||||
Limit — the host name or pattern as it is in the Semaphore inventory
|
||||
</label>
|
||||
<input id="run-limit" className="form-control" value={limit} maxLength={200} onChange={(e) => setLimit(e.target.value)} placeholder="e.g. web01" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-danger small mt-1">Not limited: it runs on every host the playbook is set up for.</div>
|
||||
)}
|
||||
</div>
|
||||
<button type="button" className="btn btn-primary" disabled={!picked || busy || (limitOn && limit.trim() === "")} onClick={() => void start()}>
|
||||
{busy ? "Starting…" : "Run"}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
{run && (
|
||||
<div className="mt-3 border-top pt-3" role="status" aria-live="polite">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2">
|
||||
<strong>{run.name}</strong>
|
||||
{run.limit && <span className="text-secondary">on {run.limit}</span>}
|
||||
<span className={`badge ${STATUS_WORDS[run.task.status]?.badge ?? "bg-secondary-lt text-secondary"}`}>{STATUS_WORDS[run.task.status]?.label ?? run.task.status}</span>
|
||||
</div>
|
||||
<div className="text-secondary small mt-1">
|
||||
Run #{run.task.id} in Semaphore{FINISHED.has(run.task.status) ? "" : " — checking every few seconds"}. The output is in Semaphore.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useState } from "react";
|
||||
import DetailDrawer from "./DetailDrawer";
|
||||
import RunPlaybook from "./RunPlaybook";
|
||||
|
||||
/** "Run…" on an alert about a server: opens a side panel to start a playbook on that server, without leaving the alerts. */
|
||||
export default function RunPlaybookButton({ serverName }: { serverName: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<button type="button" className="btn btn-sm btn-outline-secondary" title={`Run a Semaphore playbook on ${serverName}`} onClick={() => setOpen(true)}>
|
||||
Run…
|
||||
</button>
|
||||
{open && (
|
||||
<DetailDrawer title="Run a playbook" subtitle={`On ${serverName}`} onClose={() => setOpen(false)}>
|
||||
<RunPlaybook serverName={serverName} defaultLimit={serverName} />
|
||||
</DetailDrawer>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type ServerRecord, type ServerRelation } from "../api/client";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/**
|
||||
* Which server this one runs on (a virtual machine on its host). When the host stops reporting, this server's own "offline" alert is
|
||||
* folded under the host's instead of being a second one. Left alone it is worked out from the Proxmox node the server is linked to;
|
||||
* an admin can say it by hand. Everyone sees it; only admins change it.
|
||||
*/
|
||||
export default function RunsOn({ serverId, parent, canEdit, onChanged }: { serverId: number; parent: ServerRelation | null; canEdit: boolean; onChanged: () => void }) {
|
||||
const [servers, setServers] = useState<ServerRecord[] | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canEdit) return;
|
||||
api.servers
|
||||
.list()
|
||||
.then((res) => setServers(res.servers))
|
||||
.catch(() => setServers([]));
|
||||
}, [canEdit]);
|
||||
|
||||
async function change(value: string) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.servers.update(serverId, { parentServerId: value === "" ? null : Number(value) });
|
||||
toast.success(value === "" ? "Back to working it out from the Proxmox node." : "Saved.");
|
||||
onChanged();
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!canEdit) {
|
||||
return parent ? <Link to={`/servers/${parent.id}`}>{parent.name}</Link> : <span className="text-secondary">—</span>;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<select className="form-select form-select-sm" aria-label="The server this one runs on" value={parent && !parent.auto ? String(parent.id) : ""} disabled={busy || servers === null} onChange={(e) => void change(e.target.value)}>
|
||||
<option value="">{parent?.auto ? `Automatic: ${parent.name}` : "None (automatic)"}</option>
|
||||
{(servers ?? [])
|
||||
.filter((s) => s.id !== serverId)
|
||||
.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">Automatic means worked out from its Proxmox node. If it stops reporting, this server's offline alert is folded under its host's.</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -27,10 +27,12 @@ export default function StatusStrip() {
|
||||
.filter((a) => !a.silenced && a.severity !== "info")
|
||||
.sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
|
||||
const silenced = report.counts.silenced;
|
||||
const grouped = report.counts.grouped ?? 0;
|
||||
const blind = report.couldntCheck.length;
|
||||
|
||||
const notes: string[] = [];
|
||||
if (silenced > 0) notes.push(`${silenced} silenced by maintenance`);
|
||||
if (grouped > 0) notes.push(`${grouped} more explained by a server that is down`);
|
||||
if (blind > 0 && badge) notes.push(`${blind} check${blind === 1 ? "" : "s"} couldn't run`);
|
||||
|
||||
if (!badge) {
|
||||
@@ -50,6 +52,7 @@ export default function StatusStrip() {
|
||||
<span className="text-secondary">No active alerts.</span>
|
||||
)}
|
||||
{silenced > 0 && <span className="text-secondary"> {silenced} silenced by maintenance.</span>}
|
||||
{grouped > 0 && <span className="text-secondary"> {grouped} more explained by a server that is down.</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { PendingUpdates } from "../api/client";
|
||||
|
||||
/**
|
||||
* What a server has waiting: "Up to date", "5 waiting" or "5 waiting, 2 security" (red when any are security fixes), and a
|
||||
* "restart needed" beside it. Says "not reported" when the agent hasn't said — never "up to date" for a server that simply didn't tell us.
|
||||
*/
|
||||
export default function UpdatesBadge({ updates }: { updates: PendingUpdates | null }) {
|
||||
if (!updates) {
|
||||
return (
|
||||
<span className="badge bg-secondary-lt text-secondary" title="This server's agent hasn't reported updates — it may be an older agent, or its package manager isn't one it can ask.">
|
||||
not reported
|
||||
</span>
|
||||
);
|
||||
}
|
||||
const security = updates.security ?? 0;
|
||||
const level = updates.count === 0 ? "bg-green-lt text-green" : security > 0 ? "bg-red-lt text-red" : "bg-yellow-lt text-yellow";
|
||||
return (
|
||||
<span className="d-inline-flex flex-wrap align-items-center gap-1">
|
||||
<span className={`badge ${level}`}>
|
||||
{updates.count === 0 ? "Up to date" : `${updates.count} waiting${security > 0 ? `, ${security} security` : ""}`}
|
||||
</span>
|
||||
{updates.rebootRequired && <span className="badge bg-orange-lt text-orange">restart needed</span>}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user