Dependencies beyond servers, web push, inventory auto-fill with QR labels, Windows agent health

- Dependencies: servers and integrations can depend on each other; alerts are folded under the root cause, and a failure explained by something down isn't announced
- Web push: hand-written VAPID and RFC 8291 encryption, per-device subscriptions, a fifth notification channel, service worker handlers
- Inventory: maker/model/serial from the agents fill blank fields, "Refresh from agent", QR label printing and ?asset= deep links
- Windows agent (v4) reports failed services, disk health, Storage Spaces pools and hardware identity; Linux agent (v5) reports hardware identity

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-18 18:53:30 +02:00
1 parent 5cc51c57de
commit ec9c2f73f0
55 files changed
+12553 -65

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
import { Router } from "express";
import { eq } from "drizzle-orm";
import { z } from "zod";
import { db } from "../db/client.js";
import { dependencies } from "../db/schema.js";
import { requireAuth, requireRole } from "../auth/middleware.js";
import { recordAudit } from "../services/audit.js";
import { invalidateAlertsCache } from "../services/alerts.js";
import { loadGraph, nodeKey, nodeTypes, wouldLoop } from "../services/dependencies.js";
import { asyncHandler } from "../utils/asyncHandler.js";
export const dependenciesRouter = Router();
dependenciesRouter.use(requireAuth);
const edgeSchema = z.object({
fromType: z.enum(nodeTypes),
fromId: z.number().int().positive(),
toType: z.enum(nodeTypes),
toId: z.number().int().positive(),
});
// Everything signed in people may see: what needs what, with the "runs on" links of servers alongside (those are set on the server itself).
dependenciesRouter.get("/", asyncHandler(async (_req, res) => {
const graph = await loadGraph();
const written = new Set(graph.rows.map((r) => `${nodeKey(r.fromType, r.fromId)}>${nodeKey(r.toType, r.toId)}`));
const runsOn: { from: string; to: string }[] = [];
for (const [from, tos] of graph.edges) for (const to of tos) if (!written.has(`${from}>${to}`)) runsOn.push({ from, to });
const nodes = [...graph.names.entries()]
.map(([key, name]) => {
const [type, id] = key.split(":");
return { key, type, id: Number(id), name };
})
.sort((a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name));
res.json({
dependencies: graph.rows
.filter((r) => graph.names.has(nodeKey(r.fromType, r.fromId)) && graph.names.has(nodeKey(r.toType, r.toId)))
.map((r) => ({ id: r.id, from: { type: r.fromType, id: r.fromId, name: graph.names.get(nodeKey(r.fromType, r.fromId))! }, to: { type: r.toType, id: r.toId, name: graph.names.get(nodeKey(r.toType, r.toId))! }, createdAt: r.createdAt })),
runsOn: runsOn.map((r) => ({ from: { key: r.from, name: graph.names.get(r.from) ?? r.from }, to: { key: r.to, name: graph.names.get(r.to) ?? r.to } })),
nodes,
});
}));
dependenciesRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
const parsed = edgeSchema.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "Say what needs what: a server or an integration each.", details: parsed.error.flatten() });
const d = parsed.data;
const graph = await loadGraph();
const from = nodeKey(d.fromType, d.fromId);
const to = nodeKey(d.toType, d.toId);
if (!graph.names.has(from) || !graph.names.has(to)) return res.status(400).json({ error: "unknown_node", message: "One of those doesn't exist." });
if (from === to) return res.status(400).json({ error: "self", message: "Something can't depend on itself." });
if (graph.edges.get(from)?.includes(to)) return res.status(409).json({ error: "duplicate", message: "That is already so." });
if (wouldLoop(graph.edges, from, to)) {
return res.status(409).json({ error: "loop", message: `${graph.names.get(to)} already depends on ${graph.names.get(from)}, so this would make them wait for each other.` });
}
const [row] = await db.insert(dependencies).values(d).returning();
await recordAudit({ actor: req.currentUser!, category: "dependency", action: "create", targetType: "dependency", targetId: row.id, detail: { from: graph.names.get(from), to: graph.names.get(to) } });
invalidateAlertsCache();
res.status(201).json({ id: row.id });
}));
dependenciesRouter.delete("/:id", requireRole("operator"), asyncHandler(async (req, res) => {
const id = /^\d+$/.test(req.params.id) ? Number(req.params.id) : NaN;
if (!Number.isInteger(id)) return res.status(400).json({ error: "invalid_id" });
const [before] = await db.select().from(dependencies).where(eq(dependencies.id, id)).limit(1);
if (!before) return res.status(404).json({ error: "not_found" });
const graph = await loadGraph();
await db.delete(dependencies).where(eq(dependencies.id, id));
await recordAudit({
actor: req.currentUser!,
category: "dependency",
action: "delete",
targetType: "dependency",
targetId: id,
detail: { from: graph.names.get(nodeKey(before.fromType as "server", before.fromId)) ?? `${before.fromType} #${before.fromId}`, to: graph.names.get(nodeKey(before.toType as "server", before.toId)) ?? `${before.toType} #${before.toId}` },
});
invalidateAlertsCache();
res.status(204).end();
}));