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
@@ -6,6 +6,8 @@ import { servers, serverLinks, integrations, dnsRecordsCache, dnsZonesCache, dns
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { generateApiToken } from "../services/tokens.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { loadParentRows, resolveParents, wouldLoop } from "../services/serverParents.js";
|
||||
import { parsePendingUpdates } from "../services/pendingUpdates.js";
|
||||
import { getServerMetrics, RETENTION_DAYS } from "../services/serverMetrics.js";
|
||||
import { getServerActivity } from "../services/serverActivity.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
@@ -21,9 +23,9 @@ import { getSettings } from "../services/settingsStore.js";
|
||||
export const serversRouter = Router();
|
||||
|
||||
/** A server row as the API returns it: no token hash, and tags as an array rather than the stored JSON. */
|
||||
function publicServer<T extends { apiTokenHash: string; tags: string | null }>(row: T) {
|
||||
const { apiTokenHash: _hash, tags, ...rest } = row;
|
||||
return { ...rest, tags: parseTags(tags) };
|
||||
function publicServer<T extends { apiTokenHash: string; tags: string | null; pendingUpdates: string | null }>(row: T) {
|
||||
const { apiTokenHash: _hash, tags, pendingUpdates, ...rest } = row;
|
||||
return { ...rest, tags: parseTags(tags), pendingUpdates: parsePendingUpdates(pendingUpdates) };
|
||||
}
|
||||
|
||||
serversRouter.use(requireAuth);
|
||||
@@ -113,6 +115,8 @@ const updateServerSchema = z
|
||||
proxmoxGuestType: z.enum(["qemu", "lxc"]).nullable().optional(),
|
||||
proxmoxVmid: z.number().int().nullable().optional(),
|
||||
hideProxmoxLink: z.boolean().optional(),
|
||||
// The server this one runs on. Null goes back to working it out from the Proxmox node.
|
||||
parentServerId: z.number().int().nullable().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
@@ -148,6 +152,17 @@ serversRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req, res)
|
||||
}
|
||||
}
|
||||
|
||||
if (parsed.data.parentServerId !== undefined && parsed.data.parentServerId !== null) {
|
||||
const parentId = parsed.data.parentServerId;
|
||||
const rows = await loadParentRows();
|
||||
if (parentId === id || !rows.some((r) => r.id === parentId)) {
|
||||
return res.status(400).json({ error: "invalid_parent", message: "Choose another server that exists." });
|
||||
}
|
||||
if (wouldLoop(rows, id, parentId)) {
|
||||
return res.status(400).json({ error: "parent_loop", message: "That server already runs on this one, so each would be waiting for the other." });
|
||||
}
|
||||
}
|
||||
|
||||
const [updated] = await db.update(servers).set(parsed.data).where(eq(servers.id, id)).returning();
|
||||
|
||||
await recordAudit({
|
||||
@@ -156,7 +171,7 @@ serversRouter.patch("/:id", requireRole("admin"), asyncHandler(async (req, res)
|
||||
action: "update",
|
||||
targetType: "server",
|
||||
targetId: id,
|
||||
detail: { name: updated.name },
|
||||
detail: { name: updated.name, ...(parsed.data.parentServerId !== undefined ? { parentServerId: parsed.data.parentServerId } : {}) },
|
||||
});
|
||||
|
||||
const serverOut = publicServer(updated);
|
||||
@@ -173,6 +188,27 @@ serversRouter.get("/summary", asyncHandler(async (_req, res) => {
|
||||
res.json(buildServerSummary(rows, healthChecks, Date.now(), await activeSubjects()));
|
||||
}));
|
||||
|
||||
// What every server that reports through an agent says is waiting to be installed, for the Updates page. Servers whose agent hasn't
|
||||
// said (it predates this, or couldn't find out) are listed with no figures rather than left out.
|
||||
serversRouter.get("/updates", asyncHandler(async (_req, res) => {
|
||||
const rows = await db
|
||||
.select({
|
||||
id: servers.id,
|
||||
name: servers.name,
|
||||
osType: servers.osType,
|
||||
lastSeenAt: servers.lastSeenAt,
|
||||
pendingUpdates: servers.pendingUpdates,
|
||||
updatesPendingSince: servers.updatesPendingSince,
|
||||
})
|
||||
.from(servers)
|
||||
.orderBy(servers.name);
|
||||
res.json({
|
||||
servers: rows
|
||||
.filter((r) => r.lastSeenAt !== null)
|
||||
.map((r) => ({ id: r.id, name: r.name, osType: r.osType, lastSeenAt: r.lastSeenAt, updates: parsePendingUpdates(r.pendingUpdates), pendingSince: r.updatesPendingSince })),
|
||||
});
|
||||
}));
|
||||
|
||||
// For the Operations > Admin Links page — every server's admin bookmarks in one place, instead of visiting
|
||||
// each server's own detail page to find them.
|
||||
serversRouter.get("/links", asyncHandler(async (_req, res) => {
|
||||
@@ -306,10 +342,21 @@ serversRouter.get("/:id/detail", asyncHandler(async (req, res) => {
|
||||
memUsedBytes: _memUsedBytes,
|
||||
listeningPorts: _listeningPorts,
|
||||
lastPortScan: _lastPortScan,
|
||||
pendingUpdates: rawUpdates,
|
||||
...serverOut
|
||||
} = server;
|
||||
|
||||
res.json({ server: { ...serverOut, tags: parseTags(rawTags) }, ipAddresses, hardware, dnsMatches, links });
|
||||
// What this server runs on, and what runs on it (set by hand, or worked out from its Proxmox node).
|
||||
const parentRows = await loadParentRows();
|
||||
const links2 = resolveParents(parentRows);
|
||||
const nameOf = new Map(parentRows.map((r) => [r.id, r.name]));
|
||||
const parentLink = links2.get(id);
|
||||
const relations = {
|
||||
parent: parentLink ? { id: parentLink.parentId, name: nameOf.get(parentLink.parentId) ?? "", auto: parentLink.auto } : null,
|
||||
children: [...links2.entries()].filter(([, l]) => l.parentId === id).map(([childId, l]) => ({ id: childId, name: nameOf.get(childId) ?? "", auto: l.auto })).sort((a, b) => a.name.localeCompare(b.name)),
|
||||
};
|
||||
|
||||
res.json({ server: { ...serverOut, tags: parseTags(rawTags), pendingUpdates: parsePendingUpdates(rawUpdates) }, ipAddresses, hardware, dnsMatches, links, relations });
|
||||
}));
|
||||
|
||||
const tagsSchema = z.object({ tags: z.array(z.string().max(100)).max(50) });
|
||||
@@ -440,6 +487,9 @@ serversRouter.delete("/:id", requireRole("admin"), asyncHandler(async (req, res)
|
||||
const id = Number(req.params.id);
|
||||
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
|
||||
|
||||
// Servers that ran on this one go back to working out where they run (the link is a plain column, not a foreign key).
|
||||
await db.update(servers).set({ parentServerId: null }).where(eq(servers.parentServerId, id));
|
||||
|
||||
const deleted = await db.delete(servers).where(eq(servers.id, id)).returning();
|
||||
if (deleted.length === 0) return res.status(404).json({ error: "not_found" });
|
||||
|
||||
|
||||
Reference in new issue
Block a user