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
@@ -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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user