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,91 @@
|
||||
/**
|
||||
* Which server runs on which: a virtual machine on its Proxmox host, a container on a Docker box. When the host stops reporting, the
|
||||
* things on it stop too, and seven alerts about seven guests only hide the one that matters — so those alerts are folded under the
|
||||
* host's. The link is either set by hand ("runs on") or worked out: a server linked to a Proxmox guest runs on the server named after
|
||||
* that guest's Proxmox node, when there is exactly one such server.
|
||||
*/
|
||||
import { db } from "../db/client.js";
|
||||
import { servers } from "../db/schema.js";
|
||||
|
||||
export interface ParentRow {
|
||||
id: number;
|
||||
name: string;
|
||||
hostname: string | null;
|
||||
parentServerId: number | null;
|
||||
proxmoxNode: string | null;
|
||||
}
|
||||
|
||||
export interface ParentLink {
|
||||
parentId: number;
|
||||
/** Worked out from the Proxmox node rather than set by hand. */
|
||||
auto: boolean;
|
||||
}
|
||||
|
||||
const lc = (s: string | null | undefined) => (s ?? "").trim().toLowerCase();
|
||||
|
||||
/** Whether a server is the machine a Proxmox node name refers to: by its name, its hostname, or the first part of a fully qualified hostname. */
|
||||
function isNode(row: ParentRow, node: string): boolean {
|
||||
const n = lc(node);
|
||||
if (!n) return false;
|
||||
const host = lc(row.hostname);
|
||||
return lc(row.name) === n || host === n || host.split(".")[0] === n;
|
||||
}
|
||||
|
||||
/** Each server's parent, where it has one. A link set by hand wins; otherwise the unique server that is its Proxmox node. */
|
||||
export function resolveParents(rows: ParentRow[]): Map<number, ParentLink> {
|
||||
const byId = new Map(rows.map((r) => [r.id, r]));
|
||||
const out = new Map<number, ParentLink>();
|
||||
for (const row of rows) {
|
||||
if (row.parentServerId !== null && row.parentServerId !== row.id && byId.has(row.parentServerId)) {
|
||||
out.set(row.id, { parentId: row.parentServerId, auto: false });
|
||||
continue;
|
||||
}
|
||||
if (row.proxmoxNode) {
|
||||
const candidates = rows.filter((r) => r.id !== row.id && isNode(r, row.proxmoxNode!));
|
||||
if (candidates.length === 1) out.set(row.id, { parentId: candidates[0].id, auto: true });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Of the servers that are down, those whose cause is another server that is down too: each maps to the topmost ancestor that is down —
|
||||
* the root cause. A chain (guest → VM host → the box it hangs off) is followed all the way up; a loop in the links covers nothing.
|
||||
*/
|
||||
export function coveredByParent(offline: Set<number>, parents: Map<number, ParentLink>): Map<number, number> {
|
||||
const covered = new Map<number, number>();
|
||||
for (const id of offline) {
|
||||
const seen = new Set<number>([id]);
|
||||
let root: number | null = null;
|
||||
let looped = false;
|
||||
let link = parents.get(id);
|
||||
while (link && !seen.has(link.parentId)) {
|
||||
if (offline.has(link.parentId)) root = link.parentId;
|
||||
seen.add(link.parentId);
|
||||
link = parents.get(link.parentId);
|
||||
}
|
||||
if (link && seen.has(link.parentId)) looped = true;
|
||||
// A loop explains nothing (each would be waiting for the other), so its members stand alone and are announced.
|
||||
if (root !== null && !looped) covered.set(id, root);
|
||||
}
|
||||
return covered;
|
||||
}
|
||||
|
||||
/** Would making `parentId` the parent of `id` close a loop? True if `id` is `parentId` or already sits above it. */
|
||||
export function wouldLoop(rows: ParentRow[], id: number, parentId: number): boolean {
|
||||
const parents = resolveParents(rows);
|
||||
const seen = new Set<number>();
|
||||
let cur: number | undefined = parentId;
|
||||
while (cur !== undefined && !seen.has(cur)) {
|
||||
if (cur === id) return true;
|
||||
seen.add(cur);
|
||||
cur = parents.get(cur)?.parentId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function loadParentRows(): Promise<ParentRow[]> {
|
||||
return db
|
||||
.select({ id: servers.id, name: servers.name, hostname: servers.hostname, parentServerId: servers.parentServerId, proxmoxNode: servers.proxmoxNode })
|
||||
.from(servers);
|
||||
}
|
||||
Reference in new issue
Block a user