UniFi integration: network devices, Wi-Fi and networks, as part of the dependency map
A UniFi controller (API key on Network 9+, or a read-only local login on any version) is read every five minutes. Its switches, access points and gateways are kept with state, IP, uptime, firmware and uplink; its networks and Wi-Fi names beside them (passphrases are never read). Nothing is written to the controller. Network > Network devices lists them. Devices are a new node type in the dependency map: uplinks become dependencies by themselves, others can be written by hand. A device offline past a limit is an offline alert, folds what depends on it, can be silenced with maintenance and have runbooks. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73a06ebe63
commit
396e074108
48 files changed
+6893
-102
No files matched your search
+55
-1
@@ -76,7 +76,7 @@ export const notificationQueue = sqliteTable("notification_queue", {
|
||||
|
||||
// ─── Maintenance windows — alerts about a target are silenced until endsAt ──
|
||||
|
||||
export const maintenanceTargetTypes = ["server", "integration", "dns_provider"] as const;
|
||||
export const maintenanceTargetTypes = ["server", "integration", "dns_provider", "device"] as const;
|
||||
export type MaintenanceTargetType = (typeof maintenanceTargetTypes)[number];
|
||||
|
||||
export const maintenanceWindows = sqliteTable("maintenance_windows", {
|
||||
@@ -515,6 +515,7 @@ export const integrationTypes = [
|
||||
"phpipam",
|
||||
"pbs",
|
||||
"osticket",
|
||||
"unifi",
|
||||
] as const;
|
||||
export type IntegrationType = (typeof integrationTypes)[number];
|
||||
|
||||
@@ -533,6 +534,59 @@ export const integrations = sqliteTable("integrations", {
|
||||
.default(sql`(current_timestamp)`),
|
||||
});
|
||||
|
||||
// Network equipment read from a UniFi controller (switches, access points, gateways), refreshed every few minutes by services/unifiSync.ts. A device is a node
|
||||
// in the dependency map ("device:<id>"), like a server, and raises an "offline" alert when the controller has not seen it online for a while.
|
||||
export const networkDevices = sqliteTable(
|
||||
"network_devices",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
integrationId: integer("integration_id")
|
||||
.notNull()
|
||||
.references(() => integrations.id, { onDelete: "cascade" }),
|
||||
externalId: text("external_id").notNull(), // the MAC address, lower case: the one thing both of UniFi's APIs give for every device
|
||||
siteName: text("site_name"),
|
||||
name: text("name").notNull(),
|
||||
model: text("model"),
|
||||
kind: text("kind").$type<"gateway" | "switch" | "access_point" | "other">().notNull().default("other"),
|
||||
ip: text("ip"),
|
||||
mac: text("mac"),
|
||||
state: text("state").$type<"online" | "offline" | "updating" | "pending" | "other">().notNull().default("other"),
|
||||
uptimeSeconds: integer("uptime_seconds"),
|
||||
firmware: text("firmware"),
|
||||
firmwareUpdatable: integer("firmware_updatable", { mode: "boolean" }).notNull().default(false),
|
||||
uplinkExternalId: text("uplink_external_id"), // the MAC of the device this one is connected through, when the controller says
|
||||
// When the controller first stopped seeing it online, kept until it is online again; the offline alert counts from here.
|
||||
offlineSince: text("offline_since"),
|
||||
lastOnlineAt: text("last_online_at"),
|
||||
firstSeenAt: text("first_seen_at").notNull(),
|
||||
updatedAt: text("updated_at").notNull(),
|
||||
},
|
||||
(t) => [uniqueIndex("network_devices_unique").on(t.integrationId, t.externalId)],
|
||||
);
|
||||
|
||||
// The networks (VLANs) and Wi-Fi names (SSIDs) a UniFi controller has set up, kept beside the devices. Passphrases are never read.
|
||||
export const networkSegments = sqliteTable(
|
||||
"network_segments",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
integrationId: integer("integration_id")
|
||||
.notNull()
|
||||
.references(() => integrations.id, { onDelete: "cascade" }),
|
||||
kind: text("kind").$type<"network" | "ssid">().notNull(),
|
||||
externalId: text("external_id").notNull(),
|
||||
siteName: text("site_name"),
|
||||
name: text("name").notNull(),
|
||||
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
|
||||
vlanId: integer("vlan_id"),
|
||||
subnet: text("subnet"), // a network's address range, e.g. 192.168.10.1/24
|
||||
purpose: text("purpose"), // a network: corporate, guest, …
|
||||
security: text("security"), // an SSID: wpa2, wpa3, open, …
|
||||
networkName: text("network_name"), // an SSID: the network its clients land on
|
||||
updatedAt: text("updated_at").notNull(),
|
||||
},
|
||||
(t) => [uniqueIndex("network_segments_unique").on(t.integrationId, t.kind, t.externalId)],
|
||||
);
|
||||
|
||||
// A port on a server that's either been seen open (by a scan or the agent) or that someone wrote a note about.
|
||||
// Rows exist only while they carry information: an open port, or one with a label/comment ("reserved").
|
||||
export const serverPorts = sqliteTable(
|
||||
|
||||
Reference in new issue
Block a user