Mirror Uptime Kuma's maintenance schedule as maintenance windows
Uptime Kuma shares its maintenance windows only over its dashboard Socket.IO connection, which takes a login. With a login username and password on the integration, "Sync schedule" on the Maintenance page (and a 15-minute background pass when switched on) reads each window's running and next time slot and the monitors it covers, and makes a maintenance window on every server those monitors match. Windows that haven't started are listed as Scheduled and silence nothing until they begin; ones ended or cancelled by hand stay ended, and ones removed in Kuma are removed here. maintenance_windows gets a source column (migration 0017) and active windows now require their start to have passed. Adds socket.io-client, and tests against a stand-in Uptime Kuma speaking the same protocol. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e416b0273
commit
9e483f2163
21 files changed
+3259
-31
No files matched your search
@@ -1,12 +1,19 @@
|
||||
import { eq, gt, lt } from "drizzle-orm";
|
||||
import { and, eq, gt, lt, lte } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { dnsProviders, integrations, maintenanceWindows, servers } from "../db/schema.js";
|
||||
|
||||
export type ActiveWindow = typeof maintenanceWindows.$inferSelect;
|
||||
|
||||
/** Windows whose end is still in the future. ISO strings compare correctly as text, so this is a plain string comparison. */
|
||||
/** Windows that have started and not yet ended. ISO strings compare correctly as text, so these are plain string comparisons. */
|
||||
export async function listActiveWindows(now: Date = new Date()): Promise<ActiveWindow[]> {
|
||||
return db.select().from(maintenanceWindows).where(gt(maintenanceWindows.endsAt, now.toISOString()));
|
||||
const t = now.toISOString();
|
||||
return db.select().from(maintenanceWindows).where(and(lte(maintenanceWindows.startedAt, t), gt(maintenanceWindows.endsAt, t)));
|
||||
}
|
||||
|
||||
/** Windows that are set up but haven't begun — the schedule mirrored from another system. They silence nothing until they start. */
|
||||
export async function listUpcomingWindows(now: Date = new Date()): Promise<ActiveWindow[]> {
|
||||
// A window cancelled before it began has its end set back to its start, and is not a window any more.
|
||||
return db.select().from(maintenanceWindows).where(and(gt(maintenanceWindows.startedAt, now.toISOString()), gt(maintenanceWindows.endsAt, maintenanceWindows.startedAt)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user