Bulk snooze, alert rules judged on report, photos on notes
Bulk snooze: Snooze... and Wake on the ticked alerts, with undo that puts back each alert's earlier snooze exactly. Alert rules are judged for a server right after its agent reports, instead of at the next 15-minute pass; only that server's rule findings change, and the check is serialized with the pass so neither overwrites the other's state. Photos on server and device notes: up to 12 each, shrunk in the browser, accepted by their own bytes (JPEG/PNG/GIF/WebP, 4 MB), kept in the database and removed with the server or device. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
251a4a9d73
commit
a16996d975
27 files changed
+8442
-54
No files matched your search
@@ -20,7 +20,7 @@ process.env.HEALTH_STARTUP_GRACE_MS = "0";
|
||||
|
||||
const express = (await import("express")).default;
|
||||
const { db } = await import("../src/db/client.js");
|
||||
const { users, servers, heartbeats, assets, alertAcks, maintenanceWindows, auditLog } = await import("../src/db/schema.js");
|
||||
const { users, servers, heartbeats, assets, alertAcks, alertSnoozes, maintenanceWindows, auditLog } = await import("../src/db/schema.js");
|
||||
const { runMigrations } = await import("../src/db/migrate.js");
|
||||
const { serversBulkRouter, alertsBulkRouter, inventoryBulkRouter } = await import("../src/routes/bulk.js");
|
||||
const { getAlerts, invalidateAlertsCache } = await import("../src/services/alerts.js");
|
||||
@@ -269,8 +269,74 @@ describe("alerts", () => {
|
||||
assert.equal((await listActiveWindows()).length, 0);
|
||||
});
|
||||
|
||||
const hoursAhead = (h: number) => new Date(Date.now() + h * 3_600_000).toISOString();
|
||||
|
||||
test("several are snoozed until the same time; one that has gone is skipped; they are hidden from the live list; undo wakes them", async () => {
|
||||
await db.delete(alertSnoozes);
|
||||
const until = hoursAhead(5);
|
||||
const r = await send("/alerts/bulk", { action: "snooze", alertIds: [...alertIds, "automation:heartbeat:99999"], until });
|
||||
assert.equal(r.status, 200);
|
||||
assert.equal(r.body.changed, 3);
|
||||
assert.deepEqual(r.body.skipped.map((x: { reason: string }) => x.reason), ["it isn't there any more"]);
|
||||
const rows = await db.select().from(alertSnoozes);
|
||||
assert.equal(rows.length, 3);
|
||||
assert.ok(rows.every((x) => x.until === new Date(until).toISOString() && x.snoozedBy === "Olga"));
|
||||
invalidateAlertsCache();
|
||||
const report = await getAlerts(true);
|
||||
assert.ok(alertIds.every((id) => report.alerts.find((a) => a.id === id)?.snoozed), "each shows as snoozed");
|
||||
assert.ok(r.body.undo.items.every((i: { previous: unknown }) => i.previous === null));
|
||||
|
||||
await send("/alerts/bulk", r.body.undo);
|
||||
assert.equal((await db.select().from(alertSnoozes)).length, 0);
|
||||
});
|
||||
|
||||
test("an earlier snooze is replaced, and undo puts it back exactly — when it ends and who made it", async () => {
|
||||
await db.delete(alertSnoozes);
|
||||
await send("/alerts/bulk", { action: "snooze", alertIds: [alertIds[0]], until: hoursAhead(2) });
|
||||
const [first] = await db.select().from(alertSnoozes);
|
||||
const over = await send("/alerts/bulk", { action: "snooze", alertIds: [alertIds[0], alertIds[1]], until: hoursAhead(30) });
|
||||
assert.equal(over.body.changed, 2);
|
||||
assert.notEqual((await db.select().from(alertSnoozes).where(eq(alertSnoozes.alertId, alertIds[0])))[0].until, first.until);
|
||||
await send("/alerts/bulk", over.body.undo);
|
||||
const rows = await db.select().from(alertSnoozes);
|
||||
assert.equal(rows.length, 1, "the second alert had none before");
|
||||
assert.deepEqual([rows[0].alertId, rows[0].until, rows[0].snoozedAt, rows[0].snoozedBy], [first.alertId, first.until, first.snoozedAt, first.snoozedBy]);
|
||||
});
|
||||
|
||||
test("snoozes are woken, those that were not snoozed are skipped, and undo puts them back", async () => {
|
||||
await db.delete(alertSnoozes);
|
||||
await send("/alerts/bulk", { action: "snooze", alertIds: [alertIds[0], alertIds[1]], until: hoursAhead(4) });
|
||||
const r = await send("/alerts/bulk", { action: "unsnooze", alertIds });
|
||||
assert.equal(r.body.changed, 2);
|
||||
assert.deepEqual(r.body.skipped.map((x: { reason: string }) => x.reason), ["it wasn't snoozed"]);
|
||||
assert.equal((await db.select().from(alertSnoozes)).length, 0);
|
||||
await send("/alerts/bulk", r.body.undo);
|
||||
assert.equal((await db.select().from(alertSnoozes)).length, 2);
|
||||
await db.delete(alertSnoozes);
|
||||
});
|
||||
|
||||
test("a time that has passed, is too far ahead or is not a time is refused, and nothing changes", async () => {
|
||||
await db.delete(alertSnoozes);
|
||||
for (const until of [hoursAhead(-1), hoursAhead(24 * 91), "tomorrow-ish"]) {
|
||||
const r = await send("/alerts/bulk", { action: "snooze", alertIds, until });
|
||||
assert.equal(r.status, 400, until);
|
||||
assert.ok(typeof r.body.message === "string" && r.body.message.length > 0);
|
||||
}
|
||||
assert.equal((await db.select().from(alertSnoozes)).length, 0);
|
||||
});
|
||||
|
||||
test("undoing to a snooze whose time has already passed drops it rather than announcing the alert at once", async () => {
|
||||
await db.delete(alertSnoozes);
|
||||
const previous = { conditionKey: "heartbeat-late:1", message: "late", until: hoursAhead(-1), snoozedBy: "Olga", snoozedAt: hoursAhead(-5) };
|
||||
await send("/alerts/bulk", { action: "snooze", alertIds: [alertIds[0]], until: hoursAhead(3) });
|
||||
const r = await send("/alerts/bulk", { action: "restore_snoozes", items: [{ alertId: alertIds[0], previous }] });
|
||||
assert.equal(r.status, 200);
|
||||
assert.equal((await db.select().from(alertSnoozes)).length, 0);
|
||||
});
|
||||
|
||||
test("an operator is needed; a viewer is not enough", async () => {
|
||||
who = "viewer";
|
||||
assert.equal((await send("/alerts/bulk", { action: "snooze", alertIds, until: hoursAhead(3) })).status, 403);
|
||||
assert.equal((await send("/alerts/bulk", { action: "acknowledge", alertIds })).status, 403);
|
||||
who = "operator";
|
||||
});
|
||||
@@ -330,7 +396,7 @@ describe("what is written down", () => {
|
||||
test("each bulk action is one audit entry saying what and how many, and the change log reads them as sentences", async () => {
|
||||
const entries = await db.select().from(auditLog);
|
||||
const actions = new Set(entries.map((e) => `${e.category}/${e.action}`));
|
||||
for (const a of ["server/bulk_tag", "maintenance/bulk_start", "maintenance/bulk_undo", "server/bulk_runs_on", "alert/bulk_ack", "alert/bulk_unack", "alert/bulk_undo", "inventory/bulk_change"]) assert.ok(actions.has(a), a);
|
||||
for (const a of ["server/bulk_tag", "maintenance/bulk_start", "maintenance/bulk_undo", "server/bulk_runs_on", "alert/bulk_ack", "alert/bulk_unack", "alert/bulk_undo", "alert/bulk_snooze", "alert/bulk_unsnooze", "inventory/bulk_change"]) assert.ok(actions.has(a), a);
|
||||
const tag = entries.find((e) => e.action === "bulk_tag" && JSON.parse(e.detail!).change === "add_tag")!;
|
||||
assert.equal(JSON.parse(tag.detail!).tag, "Nightly");
|
||||
assert.equal(JSON.parse(tag.detail!).changed, 3);
|
||||
@@ -340,6 +406,8 @@ describe("what is written down", () => {
|
||||
assert.ok(titles.some((t) => /^Tag added to 3 servers: Nightly$/.test(t)), "tag");
|
||||
assert.ok(titles.some((t) => /^Maintenance started on several at once/.test(t)), "maintenance");
|
||||
assert.ok(titles.some((t) => /alerts? acknowledged at once$/.test(t)), "ack");
|
||||
assert.ok(titles.some((t) => /alerts? snoozed at once$/.test(t)), "snooze");
|
||||
assert.ok(titles.some((t) => /^Snoozing several alerts at once was undone$/.test(t)), "snooze undo");
|
||||
assert.ok(titles.some((t) => /pieces? of hardware changed at once$/.test(t)), "hardware");
|
||||
assert.ok(titles.some((t) => /was undone$/.test(t)), "undo");
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user