Add address aliases for the Uptime Kuma maintenance sync, and ignore Kuma's "null"

Uptime Kuma often watches a host by another address than the one it was added
with here (a Proxmox host monitored over Tailscale, say). Address aliases on
the Maintenance page say that an address belongs to a server, integration or
DNS provider, so the sync puts the window there; matching stays exact.
Migration 0018 adds maintenance_aliases.

Also fixes monitors whose empty hostname/URL/port arrive from Kuma's metrics as
the text "null": they were taken as an address, hiding the real URL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-13 20:25:57 +02:00
1 parent 3e6404371b
commit 44cc9d1cf2
12 files changed
+2239 -14

No files matched your search

+12 -2
View File
@@ -13,7 +13,7 @@
*/
import { eq, like, lt } from "drizzle-orm";
import { db } from "../db/client.js";
import { dnsProviders, integrations, maintenanceWindows, servers, type MaintenanceTargetType } from "../db/schema.js";
import { dnsProviders, integrations, maintenanceAliases, maintenanceWindows, servers, type MaintenanceTargetType } from "../db/schema.js";
import { loadIntegrationConfig } from "../integrations/loadIntegration.js";
import { createUptimeKumaAdapter } from "../integrations/uptimekuma/adapter.js";
import type { KumaMaintenance } from "../integrations/uptimekuma/maintenanceFeed.js";
@@ -232,6 +232,16 @@ export async function syncKumaMaintenance(integrationId: number, now: Date = new
const host = typeof url === "string" ? hostOfAddress(url) : null;
if (host) addressed.push({ type: "dns_provider", id: p.id, name: p.name, host });
}
// Addresses someone has said belong to a server, integration or DNS provider (the Tailscale IP of a host that was added by its LAN address).
const names = new Map<string, string>();
for (const r of serverRows) names.set(`server:${r.id}`, r.name);
for (const t of addressed) names.set(`${t.type}:${t.id}`, t.name);
for (const i of await db.select({ id: integrations.id, name: integrations.name }).from(integrations)) names.set(`integration:${i.id}`, i.name);
for (const p of await db.select({ id: dnsProviders.id, name: dnsProviders.name }).from(dnsProviders)) names.set(`dns_provider:${p.id}`, p.name);
for (const a of await db.select().from(maintenanceAliases)) {
const name = names.get(`${a.targetType}:${a.targetId}`);
if (name) addressed.push({ type: a.targetType, id: a.targetId, name, host: a.address });
}
const byMonitor = new Map(monitors.map((m) => [m.id, m]));
const { desired, summary } = desiredWindows(
@@ -241,7 +251,7 @@ export async function syncKumaMaintenance(integrationId: number, now: Date = new
(id) => targetsForHost(byMonitor.get(id)?.target ?? null, matchableServers, addressed),
(id) => {
const m = byMonitor.get(id);
if (!m) return `monitor #${id}`;
if (!m) return `monitor #${id} (not in Uptime Kuma's metrics — paused?)`;
return m.target ? `${m.name} (${m.target}${m.port ? `:${m.port}` : ""})` : `${m.name} (no address)`;
},
now,