UniFi: servers plugged into switches; server page in sections; My work; settings search and undo
UniFi: the controller's client list is matched to servers by IP address, so a server is connected through a switch or access point (and port). That is a dependency made by itself, shown on the server page, the Network devices page and the Connections map. IP Addresses can sync the devices' addresses. A server's page is split into Overview, Health, Network, History, Tasks and Settings, by ?view=; alerts link to the section they are about. My work lists what has your name on it: alerts you have, maintenance you started (extend, end with undo) and update runs you started, with a badge. Settings has a search box (and the command palette lists every setting). Removing a dependency, admin link, runbook, hand-made IP address, port opening or restore test is undone from the message instead of asked about first. Two backup tests used a fixed date and failed as days passed; they follow the real clock now. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
396e074108
commit
5e26e77340
45 files changed
+6224
-194
No files matched your search
@@ -64,7 +64,7 @@ dependenciesRouter.get("/graph", asyncHandler(async (_req, res) => {
|
||||
for (const [needing, needed] of graph.edges) {
|
||||
for (const n of needed) {
|
||||
// A device connected through another is an uplink (the controller says so); a server's "runs on" is the other kind of link nobody wrote.
|
||||
edges.push({ from: n, to: needing, kind: written.has(`${needing}>${n}`) ? "written" : needing.startsWith("device:") && n.startsWith("device:") ? "uplink" : "runs-on" });
|
||||
edges.push({ from: n, to: needing, kind: written.has(`${needing}>${n}`) ? "written" : n.startsWith("device:") ? "uplink" : "runs-on" });
|
||||
taking.add(needing);
|
||||
taking.add(n);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isIP } from "node:net";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { ipamEntries, integrations, dnsRecordsCache } from "../db/schema.js";
|
||||
import { ipamEntries, integrations, dnsRecordsCache, networkDevices } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
@@ -290,6 +290,32 @@ ipamRouter.post("/sync-proxmox", requireRole("operator"), asyncHandler(async (re
|
||||
res.json({ added, updated, skipped, skippedIps, errors });
|
||||
}));
|
||||
|
||||
ipamRouter.post("/sync-unifi", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const controllers = await db.select({ id: integrations.id }).from(integrations).where(and(eq(integrations.type, "unifi"), eq(integrations.enabled, true)));
|
||||
if (controllers.length === 0) {
|
||||
return res.status(400).json({ error: "no_unifi_integration" });
|
||||
}
|
||||
let added = 0;
|
||||
let updated = 0;
|
||||
let skipped = 0;
|
||||
const skippedIps: string[] = [];
|
||||
// What was last read from the controllers (the page's own copy), not a new call: a device is as current as the Network devices page says.
|
||||
for (const d of await db.select().from(networkDevices)) {
|
||||
if (!d.ip) continue;
|
||||
const kind = d.kind.replace("_", " ");
|
||||
const notes = [`${kind}${d.model ? `, ${d.model}` : ""}`, d.mac ? `MAC ${d.mac}` : null].filter((v): v is string => !!v).join(" — ");
|
||||
const result = await upsertSyncedEntry(d.ip, d.name, "UniFi", notes, d.siteName && d.siteName !== "Default" ? d.siteName : null, "unifi");
|
||||
if (result === "added") added++;
|
||||
else if (result === "updated") updated++;
|
||||
else {
|
||||
skipped++;
|
||||
skippedIps.push(d.ip);
|
||||
}
|
||||
}
|
||||
await recordAudit({ actor: req.currentUser!, category: "ipam", action: "sync_unifi", detail: { added, updated, skipped } });
|
||||
res.json({ added, updated, skipped, skippedIps, errors: [] });
|
||||
}));
|
||||
|
||||
ipamRouter.post("/sync-phpipam", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
const phpIpamIntegrations = await db
|
||||
.select()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Router } from "express";
|
||||
import { requireAuth } from "../auth/middleware.js";
|
||||
import { buildMyWork } from "../services/myWork.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const myWorkRouter = Router();
|
||||
|
||||
myWorkRouter.use(requireAuth);
|
||||
|
||||
// What the signed-in person has taken on. Only ever their own: the answer is worked out from who is asking.
|
||||
myWorkRouter.get("/", asyncHandler(async (req, res) => {
|
||||
const user = req.currentUser!;
|
||||
res.json(await buildMyWork({ id: user.id, name: user.name ?? null, email: user.email ?? null, oidcSub: user.oidcSub }));
|
||||
}));
|
||||
@@ -2,7 +2,7 @@ import { Router } from "express";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
import { db } from "../db/client.js";
|
||||
import { integrations, networkDevices, networkSegments } from "../db/schema.js";
|
||||
import { integrations, networkDevices, networkSegments, networkServerLinks, servers } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { invalidateAlertsCache } from "../services/alerts.js";
|
||||
import { dependentsOf, loadGraph, needsOfNode, nodeKey } from "../services/dependencies.js";
|
||||
@@ -19,17 +19,31 @@ networkRouter.use(requireAuth);
|
||||
* names. Everyone signed in can see it (it is the same picture the dependency map and the alerts draw on); only starting a fresh read needs more.
|
||||
*/
|
||||
networkRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
const [intRows, devices, segments, statuses, graph, silenced] = await Promise.all([
|
||||
const [intRows, devices, segments, statuses, graph, silenced, linkRows, serverRows] = await Promise.all([
|
||||
db.select({ id: integrations.id, name: integrations.name, enabled: integrations.enabled }).from(integrations).where(eq(integrations.type, "unifi")),
|
||||
db.select().from(networkDevices),
|
||||
db.select().from(networkSegments),
|
||||
syncStatuses(),
|
||||
loadGraph(),
|
||||
activeSubjects(),
|
||||
db.select().from(networkServerLinks),
|
||||
db.select({ id: servers.id, name: servers.name }).from(servers),
|
||||
]);
|
||||
const serverName = new Map(serverRows.map((s) => [s.id, s.name]));
|
||||
const intName = new Map(intRows.map((i) => [i.id, i.name]));
|
||||
const byExternal = new Map(devices.map((d) => [`${d.integrationId}:${d.externalId}`, d]));
|
||||
// The servers plugged into each device, by what the controller says is connected (see unifiSync.matchClientsToServers).
|
||||
const plugged = new Map<number, { serverId: number; serverName: string; port: number | null; wired: boolean }[]>();
|
||||
const serverLinks: { serverId: number; serverName: string; deviceId: number; deviceName: string; port: number | null; wired: boolean }[] = [];
|
||||
for (const l of linkRows) {
|
||||
const device = byExternal.get(`${l.integrationId}:${l.deviceExternalId}`);
|
||||
const name = serverName.get(l.serverId);
|
||||
if (!device || !name) continue;
|
||||
plugged.set(device.id, [...(plugged.get(device.id) ?? []), { serverId: l.serverId, serverName: name, port: l.port, wired: l.wired }]);
|
||||
serverLinks.push({ serverId: l.serverId, serverName: name, deviceId: device.id, deviceName: device.name, port: l.port, wired: l.wired });
|
||||
}
|
||||
res.json({
|
||||
serverLinks,
|
||||
integrations: intRows.map((i) => ({ id: i.id, name: i.name, enabled: i.enabled, status: statuses[i.id] ?? null })),
|
||||
devices: devices
|
||||
.map((d) => {
|
||||
@@ -57,6 +71,7 @@ networkRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
dependents: dependentsOf(graph.edges, key).length,
|
||||
needs: needsOfNode(graph.edges, key).length,
|
||||
inMaintenance: silenced.has(key),
|
||||
servers: (plugged.get(d.id) ?? []).sort((a, b) => a.serverName.localeCompare(b.serverName)),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
|
||||
Reference in new issue
Block a user