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
@@ -28,6 +28,7 @@ import AdminLinks from "./pages/AdminLinks";
|
||||
import Alerts from "./pages/Alerts";
|
||||
import Generator from "./pages/Generator";
|
||||
import Maintenance from "./pages/Maintenance";
|
||||
import Updates from "./pages/Updates";
|
||||
import Domains from "./pages/Domains";
|
||||
import Consistency from "./pages/Consistency";
|
||||
import Privacy from "./pages/Privacy";
|
||||
@@ -136,6 +137,7 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/consistency" element={<Consistency user={user} />} />
|
||||
<Route path="/domains" element={<Domains user={user} />} />
|
||||
<Route path="/maintenance" element={<Maintenance user={user} />} />
|
||||
<Route path="/updates" element={<Updates />} />
|
||||
<Route path="/docker" element={<Docker user={user} />} />
|
||||
<Route path="/tailscale" element={<Tailscale user={user} />} />
|
||||
<Route path="/semaphore" element={<Semaphore user={user} />} />
|
||||
|
||||
+78
-3
@@ -490,6 +490,38 @@ export interface ServerRecord {
|
||||
proxmoxVmid: number | null;
|
||||
hideProxmoxLink: boolean;
|
||||
tags: string[];
|
||||
/** The server this one runs on, when an admin said so; null means it is worked out from the Proxmox node. */
|
||||
parentServerId: number | null;
|
||||
/** What the agent says is waiting to be installed; null until it has said. */
|
||||
pendingUpdates: PendingUpdates | null;
|
||||
/** When updates were first seen waiting (and none were before); null when none are. */
|
||||
updatesPendingSince: string | null;
|
||||
}
|
||||
|
||||
export interface PendingUpdates {
|
||||
manager: string;
|
||||
count: number;
|
||||
/** Null when the package manager can't say which are security fixes. */
|
||||
security: number | null;
|
||||
rebootRequired: boolean;
|
||||
reportedAt: string;
|
||||
}
|
||||
|
||||
/** One server on the Updates page. */
|
||||
export interface UpdatesServer {
|
||||
id: number;
|
||||
name: string;
|
||||
osType: string;
|
||||
lastSeenAt: string | null;
|
||||
updates: PendingUpdates | null;
|
||||
pendingSince: string | null;
|
||||
}
|
||||
|
||||
/** What a server runs on, and what runs on it. `auto`: worked out from the Proxmox node rather than set by hand. */
|
||||
export interface ServerRelation {
|
||||
id: number;
|
||||
name: string;
|
||||
auto: boolean;
|
||||
}
|
||||
|
||||
export interface ServerHardware {
|
||||
@@ -531,6 +563,7 @@ export interface ServerDetail {
|
||||
hardware: ServerHardware;
|
||||
dnsMatches: DnsMatch[];
|
||||
links: ServerLink[];
|
||||
relations: { parent: ServerRelation | null; children: ServerRelation[] };
|
||||
}
|
||||
|
||||
export type AlertSeverity = "critical" | "warning" | "info";
|
||||
@@ -547,6 +580,10 @@ export interface AlertItem {
|
||||
silenced: boolean;
|
||||
/** What a maintenance window would go on to silence it — what the Silence button acts on. Null when nothing can silence it. */
|
||||
target?: { type: MaintenanceTargetType; id: number; name: string } | null;
|
||||
/** Held back because another problem explains it (a guest down because its host is): the host's alert says so too. */
|
||||
causedBy?: { name: string };
|
||||
/** On a host's alert: the servers on it whose own alerts are folded under this one. */
|
||||
affects?: string[];
|
||||
/** The osTicket ticket opened for it, if one was. */
|
||||
ticket?: { number: string | null; url: string | null; grouped: boolean; openedAt: string | null } | null;
|
||||
}
|
||||
@@ -590,7 +627,7 @@ export interface AlertTicketOverview {
|
||||
|
||||
export interface AlertsReport {
|
||||
alerts: AlertItem[];
|
||||
counts: { critical: number; warning: number; info: number; silenced: number };
|
||||
counts: { critical: number; warning: number; info: number; silenced: number; grouped: number };
|
||||
couldntCheck: { name: string; error: string; affects: string[] }[];
|
||||
notes: string[];
|
||||
generatedAt: string;
|
||||
@@ -654,6 +691,34 @@ export interface ServerUpdateInput {
|
||||
proxmoxGuestType?: "qemu" | "lxc" | null;
|
||||
proxmoxVmid?: number | null;
|
||||
hideProxmoxLink?: boolean;
|
||||
/** The server this one runs on; null goes back to working it out from the Proxmox node. */
|
||||
parentServerId?: number | null;
|
||||
}
|
||||
|
||||
/** A maintenance that repeats: "every Sunday 02:00–04:00 on these servers". */
|
||||
export interface MaintenanceSchedule {
|
||||
id: number;
|
||||
name: string;
|
||||
reason: string | null;
|
||||
/** 0 = Sunday … 6 = Saturday. */
|
||||
days: number[];
|
||||
startTime: string;
|
||||
durationMinutes: number;
|
||||
timezone: string;
|
||||
enabled: boolean;
|
||||
createdBy: string | null;
|
||||
targets: { type: MaintenanceTargetType; id: number; name: string; kind: string }[];
|
||||
nextStart: string | null;
|
||||
}
|
||||
|
||||
export interface MaintenanceScheduleInput {
|
||||
name: string;
|
||||
reason?: string;
|
||||
targets: { type: MaintenanceTargetType; id: number }[];
|
||||
days: number[];
|
||||
startTime: string;
|
||||
durationMinutes: number;
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
export type ScheduleType = "cron" | "systemd_timer" | "windows_task" | "docker" | "backup" | "update" | "n8n_workflow" | "manual";
|
||||
@@ -1230,6 +1295,12 @@ export const api = {
|
||||
startBulk: (data: { scope: MaintenanceBulkScope; minutes: number; reason?: string }) =>
|
||||
request<{ started: number; extended: number; total: number }>("/api/maintenance/bulk", { method: "POST", body: JSON.stringify(data) }),
|
||||
endAll: () => request<{ ended: number }>("/api/maintenance/end-all", { method: "POST" }),
|
||||
schedules: {
|
||||
list: () => request<{ schedules: MaintenanceSchedule[] }>("/api/maintenance/schedules"),
|
||||
create: (data: MaintenanceScheduleInput) => request<{ id: number; windowsMade: number }>("/api/maintenance/schedules", { method: "POST", body: JSON.stringify(data) }),
|
||||
setEnabled: (id: number, enabled: boolean) => request<{ enabled: boolean }>(`/api/maintenance/schedules/${id}`, { method: "PATCH", body: JSON.stringify({ enabled }) }),
|
||||
remove: (id: number) => request<void>(`/api/maintenance/schedules/${id}`, { method: "DELETE" }),
|
||||
},
|
||||
syncUptimeKuma: (data: { integrationId: number }) =>
|
||||
request<UptimeKumaSyncResult>("/api/maintenance/sync/uptimekuma", { method: "POST", body: JSON.stringify(data) }),
|
||||
importUptimeKuma: (data: { integrationId: number; minutes: number }) =>
|
||||
@@ -1387,6 +1458,7 @@ export const api = {
|
||||
update: (id: number, data: ServerUpdateInput) =>
|
||||
request<{ server: ServerRecord }>(`/api/servers/${id}`, { method: "PATCH", body: JSON.stringify(data) }),
|
||||
summary: () => request<ServerSummary>("/api/servers/summary"),
|
||||
updates: () => request<{ servers: UpdatesServer[] }>("/api/servers/updates"),
|
||||
detail: (id: number) => request<ServerDetail>(`/api/servers/${id}/detail`),
|
||||
activity: (id: number) => request<{ events: ServerActivityEvent[] }>(`/api/servers/${id}/activity`),
|
||||
metrics: (id: number, days: number) => request<{ days: number; series: ServerMetricSeries[] }>(`/api/servers/${id}/metrics?days=${days}`),
|
||||
@@ -1552,11 +1624,14 @@ export const api = {
|
||||
semaphore: {
|
||||
templates: (integrationId: number) =>
|
||||
request<SemaphoreTemplatesResponse>(`/api/integrations/${integrationId}/semaphore/templates`),
|
||||
run: (integrationId: number, projectId: number, templateId: number) =>
|
||||
/** `limit` runs it on those hosts only (ansible's --limit). */
|
||||
run: (integrationId: number, projectId: number, templateId: number, options?: { limit?: string }) =>
|
||||
request<{ task: SemaphoreTask }>(
|
||||
`/api/integrations/${integrationId}/semaphore/projects/${projectId}/templates/${templateId}/run`,
|
||||
{ method: "POST" },
|
||||
{ method: "POST", body: JSON.stringify(options ?? {}) },
|
||||
),
|
||||
task: (integrationId: number, projectId: number, taskId: number) =>
|
||||
request<{ task: SemaphoreTask }>(`/api/integrations/${integrationId}/semaphore/projects/${projectId}/tasks/${taskId}`),
|
||||
},
|
||||
proxmox: {
|
||||
guests: (integrationId: number) => request<ProxmoxGuestsResponse>(`/api/integrations/${integrationId}/proxmox/guests`),
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
IconWorldWww,
|
||||
IconListCheck,
|
||||
IconRefresh,
|
||||
IconDownload,
|
||||
IconActivityHeartbeat,
|
||||
IconShieldCheck,
|
||||
IconTicket,
|
||||
@@ -101,6 +102,7 @@ export const NAV: NavEntry[] = [
|
||||
items: [
|
||||
{ to: "/alerts", label: "Alerts", icon: <IconAlertTriangle size={20} /> },
|
||||
{ to: "/maintenance", label: "Maintenance", icon: <IconTool size={20} /> },
|
||||
{ to: "/updates", label: "Updates", icon: <IconDownload size={20} /> },
|
||||
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
|
||||
{ to: "/osticket", label: "osTicket", icon: <IconTicket size={20} /> },
|
||||
{ to: "/admin-links", label: "Admin Links", icon: <IconExternalLink size={20} /> },
|
||||
|
||||
@@ -13,6 +13,7 @@ export const GO_SHORTCUTS: GoShortcut[] = [
|
||||
{ key: "a", to: "/alerts", label: "Alerts" },
|
||||
{ key: "s", to: "/servers", label: "Servers" },
|
||||
{ key: "m", to: "/maintenance", label: "Maintenance" },
|
||||
{ key: "u", to: "/updates", label: "Updates" },
|
||||
{ key: "i", to: "/integrations", label: "Integrations" },
|
||||
{ key: "k", to: "/secrets", label: "Secrets" },
|
||||
{ key: "p", to: "/map", label: "Map" },
|
||||
|
||||
@@ -12,6 +12,7 @@ import { readableError } from "../utils/errors";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import SilenceButton from "../components/SilenceButton";
|
||||
import RunPlaybookButton from "../components/RunPlaybookButton";
|
||||
|
||||
const SEVERITY: Record<AlertSeverity, { label: string; badge: string; rank: number }> = {
|
||||
critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 },
|
||||
@@ -89,6 +90,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
{ label: "Warnings", value: counts?.warning, color: "text-yellow" },
|
||||
{ label: "Info", value: counts?.info, color: "text-blue" },
|
||||
{ label: "Silenced (maintenance)", value: counts?.silenced, color: "text-secondary" },
|
||||
...((counts?.grouped ?? 0) > 0 ? [{ label: "Grouped under another", value: counts?.grouped, color: "text-secondary" }] : []),
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -196,10 +198,10 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{(counts?.silenced ?? 0) > 0 && (
|
||||
{(counts?.silenced ?? 0) + (counts?.grouped ?? 0) > 0 && (
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={showSilenced} onChange={(e) => setShowSilenced(e.target.checked)} />
|
||||
<span className="form-check-label">Show silenced</span>
|
||||
<span className="form-check-label">{(counts?.grouped ?? 0) > 0 ? "Show silenced and grouped" : "Show silenced"}</span>
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
@@ -230,10 +232,21 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
<td>{a.link ? <Link to={a.link}>{a.source}</Link> : a.source}</td>
|
||||
<td>
|
||||
{a.message}
|
||||
{a.silenced && (
|
||||
<span className="badge bg-secondary-lt text-secondary ms-2" title="Under a maintenance window — notifications for this are held back">
|
||||
silenced
|
||||
{a.causedBy ? (
|
||||
<span className="badge bg-secondary-lt text-secondary ms-2" title={`${a.causedBy.name} is down too, which explains this — notifications for this are held back. If ${a.causedBy.name} comes back and this stays down, it alerts then.`}>
|
||||
caused by {a.causedBy.name}
|
||||
</span>
|
||||
) : (
|
||||
a.silenced && (
|
||||
<span className="badge bg-secondary-lt text-secondary ms-2" title="Under a maintenance window — notifications for this are held back">
|
||||
silenced
|
||||
</span>
|
||||
)
|
||||
)}
|
||||
{a.affects && a.affects.length > 0 && (
|
||||
<div className="text-secondary small">
|
||||
Also takes down {a.affects.length} {a.affects.length === 1 ? "server" : "servers"}: {a.affects.join(", ")}
|
||||
</div>
|
||||
)}
|
||||
{a.ticket &&
|
||||
(() => {
|
||||
@@ -252,7 +265,10 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</td>
|
||||
{canSilence && (
|
||||
<td className="text-nowrap">
|
||||
<SilenceButton alert={a} onDone={() => void load(true)} />
|
||||
<div className="btn-list flex-nowrap">
|
||||
<SilenceButton alert={a} onDone={() => void load(true)} />
|
||||
{a.target?.type === "server" && !a.silenced && <RunPlaybookButton serverName={a.target.name} />}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
|
||||
@@ -18,6 +18,7 @@ import { ErrorNotice } from "../components/Notice";
|
||||
import { toast } from "../utils/toast";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import MaintenanceTimeline from "../components/MaintenanceTimeline";
|
||||
import RecurringMaintenance from "../components/RecurringMaintenance";
|
||||
|
||||
const DURATIONS: { minutes: number; label: string }[] = [
|
||||
{ minutes: 30, label: "30 minutes" },
|
||||
@@ -326,6 +327,15 @@ export default function Maintenance({ user }: { user: CurrentUser }) {
|
||||
|
||||
{((windows?.length ?? 0) > 0 || upcoming.length > 0) && <MaintenanceTimeline windows={[...(windows ?? []), ...upcoming]} now={now} />}
|
||||
|
||||
<RecurringMaintenance
|
||||
canEdit={canEdit}
|
||||
targets={targets}
|
||||
onChanged={() => {
|
||||
load();
|
||||
announceChange();
|
||||
}}
|
||||
/>
|
||||
|
||||
{canEdit && kumaIntegrations && kumaIntegrations.length > 0 && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
|
||||
@@ -17,6 +17,9 @@ import ServerTrends from "../components/ServerTrends";
|
||||
import ServerActivity from "../components/ServerActivity";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import UptimeRibbon from "../components/UptimeRibbon";
|
||||
import RunsOn from "../components/RunsOn";
|
||||
import RunPlaybook from "../components/RunPlaybook";
|
||||
import UpdatesBadge from "../components/UpdatesBadge";
|
||||
import ServerTags from "../components/ServerTags";
|
||||
import ServerTaskTable, { SCHEDULE_TYPE_LABELS } from "../components/ServerTaskTable";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
@@ -755,6 +758,36 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
|
||||
<dd className="col-7">
|
||||
<UptimeRibbon kind="servers" id={server.id} name={server.name} />
|
||||
</dd>
|
||||
<dt className="col-5">Runs on</dt>
|
||||
<dd className="col-7">
|
||||
<RunsOn serverId={server.id} parent={detail.relations.parent} canEdit={isAdmin} onChanged={() => void loadDetail()} />
|
||||
</dd>
|
||||
{detail.relations.children.length > 0 && (
|
||||
<>
|
||||
<dt className="col-5">Runs here</dt>
|
||||
<dd className="col-7">
|
||||
{detail.relations.children.map((c, i) => (
|
||||
<span key={c.id}>
|
||||
{i > 0 && ", "}
|
||||
<Link to={`/servers/${c.id}`}>{c.name}</Link>
|
||||
</span>
|
||||
))}
|
||||
</dd>
|
||||
</>
|
||||
)}
|
||||
{server.lastSeenAt && (
|
||||
<>
|
||||
<dt className="col-5">Updates</dt>
|
||||
<dd className="col-7">
|
||||
<UpdatesBadge updates={server.pendingUpdates} />
|
||||
{server.updatesPendingSince && server.pendingUpdates && server.pendingUpdates.count > 0 && (
|
||||
<div className="text-secondary small">
|
||||
waiting since <TimeAgo value={server.updatesPendingSince} />
|
||||
</div>
|
||||
)}
|
||||
</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
@@ -763,6 +796,16 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
|
||||
|
||||
{hardware.source === "agent" && <ServerTrends serverId={serverId} />}
|
||||
{(user.role === "admin" || user.role === "operator") && <ServerActivity serverId={serverId} />}
|
||||
{canEditTasks && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Run a playbook</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<RunPlaybook serverName={server.name} defaultLimit={server.name} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ServerPorts
|
||||
serverId={serverId}
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type DockhandContainer, type UpdatesServer } from "../api/client";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import UpdatesBadge from "../components/UpdatesBadge";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
interface Row {
|
||||
id: number;
|
||||
name: string;
|
||||
os: string;
|
||||
manager: string;
|
||||
/** Null: the agent hasn't said. */
|
||||
count: number | null;
|
||||
security: number | null;
|
||||
restart: boolean;
|
||||
/** ISO — when updates were first seen waiting. */
|
||||
since: string | null;
|
||||
reportedAt: string | null;
|
||||
server: UpdatesServer;
|
||||
}
|
||||
|
||||
function toRow(s: UpdatesServer): Row {
|
||||
return {
|
||||
id: s.id,
|
||||
name: s.name,
|
||||
os: s.osType,
|
||||
manager: s.updates?.manager ?? "",
|
||||
count: s.updates ? s.updates.count : null,
|
||||
security: s.updates ? s.updates.security : null,
|
||||
restart: s.updates?.rebootRequired ?? false,
|
||||
since: s.pendingSince,
|
||||
reportedAt: s.updates?.reportedAt || null,
|
||||
server: s,
|
||||
};
|
||||
}
|
||||
|
||||
const DAY_MS = 86_400_000;
|
||||
|
||||
/**
|
||||
* What is waiting to be installed, in one place: the updates each server's agent says are pending (how many, how many are security fixes,
|
||||
* whether a restart is due, and how long they have been waiting) and the Docker containers that have a newer image. It only looks —
|
||||
* nothing here installs anything.
|
||||
*/
|
||||
export default function Updates() {
|
||||
const [servers, setServers] = useState<UpdatesServer[] | null>(null);
|
||||
const [containers, setContainers] = useState<(DockhandContainer & { integrationName: string })[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [onlyWaiting, setOnlyWaiting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api.servers
|
||||
.updates()
|
||||
.then((res) => alive && setServers(res.servers))
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
api.integrations
|
||||
.list()
|
||||
.then(async (res) => {
|
||||
const docker = res.integrations.filter((i) => i.type === "dockhand" && i.enabled);
|
||||
const all = await Promise.all(
|
||||
docker.map((i) =>
|
||||
api.integrations.dockhand
|
||||
.containers(i.id)
|
||||
.then((r) => r.containers.map((c) => ({ ...c, integrationName: i.name })))
|
||||
.catch(() => []),
|
||||
),
|
||||
);
|
||||
if (alive) setContainers(docker.length === 0 ? null : all.flat().filter((c) => c.updateAvailable === true));
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const rows = (servers ?? []).map(toRow);
|
||||
const waiting = rows.filter((r) => (r.count ?? 0) > 0);
|
||||
const tableSearch = useTableSearch(onlyWaiting ? waiting : rows);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "security", "desc", { url: true });
|
||||
|
||||
const reporting = rows.filter((r) => r.count !== null).length;
|
||||
const securityTotal = rows.reduce((n, r) => n + (r.security ?? 0), 0);
|
||||
const restarts = rows.filter((r) => r.restart).length;
|
||||
const oldest = waiting.map((r) => r.since).filter((s): s is string => !!s).sort()[0];
|
||||
const notReporting = rows.length - reporting;
|
||||
|
||||
function exportCsv() {
|
||||
if (!sorted) return;
|
||||
downloadCsv(
|
||||
"updates.csv",
|
||||
["Server", "Package manager", "Waiting", "Security", "Restart needed", "Waiting since", "Reported"],
|
||||
sorted.map((r) => [r.name, r.manager, r.count ?? "", r.security ?? "", r.restart ? "yes" : "no", r.since ?? "", r.reportedAt ?? ""]),
|
||||
);
|
||||
}
|
||||
|
||||
const cards: { label: string; value: string | number; note?: string; color: string }[] = [
|
||||
{ label: "Servers with updates waiting", value: servers ? `${waiting.length} of ${reporting}` : "…", note: notReporting > 0 ? `${notReporting} haven't reported updates` : undefined, color: waiting.length > 0 ? "text-yellow" : "text-green" },
|
||||
{ label: "Security updates waiting", value: servers ? securityTotal : "…", color: securityTotal > 0 ? "text-red" : "text-green" },
|
||||
{ label: "Need a restart", value: servers ? restarts : "…", color: restarts > 0 ? "text-orange" : "text-green" },
|
||||
{ label: "Longest wait", value: oldest ? `${Math.max(1, Math.floor((Date.now() - Date.parse(oldest)) / DAY_MS))} d` : servers ? "—" : "…", color: "text-secondary" },
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<h2 className="page-title mb-0">Updates</h2>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
What the agents say is waiting to be installed on each server, and the Docker containers that have a newer image. This page only looks — it installs nothing. To apply updates, run a playbook from the server's page.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-lg-3" key={c.label}>
|
||||
<div className="card card-sm">
|
||||
<div className="card-body">
|
||||
<div className={`h2 mb-0 ${c.color}`}>{c.value}</div>
|
||||
<div className="text-secondary">{c.label}</div>
|
||||
{c.note && <div className="text-secondary small">{c.note}</div>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<TableToolbar
|
||||
search={tableSearch.query}
|
||||
onSearch={tableSearch.setQuery}
|
||||
placeholder="Search servers…"
|
||||
filters={
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={onlyWaiting} onChange={(e) => setOnlyWaiting(e.target.checked)} />
|
||||
<span className="form-check-label">Only those with updates</span>
|
||||
</label>
|
||||
}
|
||||
shown={sorted?.length}
|
||||
total={onlyWaiting ? waiting.length : 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="Server" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Updates" sortKeyName="count" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Security" sortKeyName="security" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Waiting since" sortKeyName="since" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Reported" sortKeyName="reportedAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{servers === null && !error && (
|
||||
<tr>
|
||||
<td colSpan={5}>
|
||||
<BlockSkeleton lines={3} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{sorted?.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td>
|
||||
<Link to={`/servers/${r.id}`}>{r.name}</Link> <span className="text-secondary small">{r.manager}</span>
|
||||
</td>
|
||||
<td>
|
||||
<UpdatesBadge updates={r.server.updates} />
|
||||
</td>
|
||||
<td>{r.security === null ? <span className="text-secondary">—</span> : r.security}</td>
|
||||
<td className="text-secondary">{r.since ? <TimeAgo value={r.since} /> : "—"}</td>
|
||||
<td className="text-secondary">{r.reportedAt ? <TimeAgo value={r.reportedAt} /> : "—"}</td>
|
||||
</tr>
|
||||
))}
|
||||
{servers !== null && sorted?.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={5} className="text-secondary text-center">
|
||||
{tableSearch.active || onlyWaiting ? "Nothing matches that." : "No server has reported yet."}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{notReporting > 0 && (
|
||||
<div className="card-footer text-secondary small">
|
||||
“Not reported” means that server's agent hasn't said — it may be an older agent (run its install command again, from Servers → Manage servers, to update it), or its package manager isn't apt, dnf, zypper or Windows Update.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{containers !== null && (
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Docker containers with a newer image</h3>
|
||||
</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Container</th>
|
||||
<th>Image</th>
|
||||
<th>Newer version</th>
|
||||
<th>Where</th>
|
||||
<th>Checked</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{containers.map((c) => (
|
||||
<tr key={`${c.integrationName}:${c.environmentId}:${c.id}`}>
|
||||
<td>
|
||||
<Link to="/docker">{c.name}</Link>
|
||||
</td>
|
||||
<td className="text-secondary">{c.image}</td>
|
||||
<td>{c.newerVersion ?? "—"}</td>
|
||||
<td className="text-secondary">{c.environmentName}</td>
|
||||
<td className="text-secondary">
|
||||
<TimeAgo value={c.checkedAt} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{containers.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={5} className="text-secondary text-center">
|
||||
Every container is on its latest image, as far as the last check could tell.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -671,6 +671,11 @@ main:focus {
|
||||
background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.45) 0 3px, transparent 3px 6px);
|
||||
}
|
||||
|
||||
/* Windows made from a recurring schedule get vertical stripes. */
|
||||
.timeline-bar-recurring {
|
||||
background-image: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.5) 0 2px, transparent 2px 5px);
|
||||
}
|
||||
|
||||
/* ── The wall display: a full-screen status board, big enough to read across a room. ── */
|
||||
.wall {
|
||||
display: flex;
|
||||
|
||||
Reference in new issue
Block a user