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
@@ -7,7 +7,7 @@
|
||||
* past its limit on every sample for that long. A disk's temperature is only known as of its last report, so it is judged right now. A server that is not reporting is not
|
||||
* judged — its own offline alert says that.
|
||||
*/
|
||||
import { eq, gte } from "drizzle-orm";
|
||||
import { and, eq, gte } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { alertRules, serverMetrics, servers, type AlertRuleMetric } from "../db/schema.js";
|
||||
import { parseHostHealth } from "./hostHealth.js";
|
||||
@@ -128,11 +128,12 @@ export async function listRules(): Promise<RuleRow[]> {
|
||||
return (await db.select().from(alertRules)).sort((a, b) => a.name.localeCompare(b.name) || a.id - b.id);
|
||||
}
|
||||
|
||||
/** What the given rules find right now, from the stored history. Reads nothing when no rule is on. */
|
||||
export async function computeRuleFindings(rules: RuleRow[], now: number = Date.now()): Promise<RuleFinding[]> {
|
||||
/** What the given rules find right now, from the stored history — on one server only when `onlyServerId` is given, which reads only that server's history. Reads nothing when no rule is on. */
|
||||
export async function computeRuleFindings(rules: RuleRow[], now: number = Date.now(), onlyServerId?: number): Promise<RuleFinding[]> {
|
||||
const on = rules.filter((r) => r.enabled);
|
||||
if (on.length === 0) return [];
|
||||
const rows = await db.select({ id: servers.id, name: servers.name, tags: servers.tags, hostHealth: servers.hostHealth }).from(servers);
|
||||
const everything = db.select({ id: servers.id, name: servers.name, tags: servers.tags, hostHealth: servers.hostHealth }).from(servers);
|
||||
const rows = await (onlyServerId === undefined ? everything : everything.where(eq(servers.id, onlyServerId)));
|
||||
const serverList: RuleServer[] = rows.map((r) => ({
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
@@ -143,7 +144,8 @@ export async function computeRuleFindings(rules: RuleRow[], now: number = Date.n
|
||||
if (on.some((r) => r.metric !== "disk_temp")) {
|
||||
const longest = Math.max(...on.filter((r) => r.metric !== "disk_temp").map((r) => r.forMinutes));
|
||||
const since = new Date(now - (longest * 60_000 + 3 * 3600_000)).toISOString();
|
||||
for (const r of await db.select().from(serverMetrics).where(gte(serverMetrics.recordedAt, since))) {
|
||||
const recent = gte(serverMetrics.recordedAt, since);
|
||||
for (const r of await db.select().from(serverMetrics).where(onlyServerId === undefined ? recent : and(recent, eq(serverMetrics.serverId, onlyServerId)))) {
|
||||
if (r.metric !== "cpu" && r.metric !== "mem" && !r.metric.startsWith("disk:")) continue;
|
||||
const k = sampleKey(r.serverId, r.metric);
|
||||
const list = samples.get(k) ?? [];
|
||||
|
||||
Reference in new issue
Block a user