From 75ef6c934d4da239d42187198999ad2be7ae885f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 4 Dec 2025 21:52:50 +0000 Subject: [PATCH] add monitor thresholds --- server/src/db/models/monitors/Monitor.ts | 19 +++++++++++++++++++ .../src/services/business/MonitorService.ts | 1 + server/src/validation/index.ts | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/server/src/db/models/monitors/Monitor.ts b/server/src/db/models/monitors/Monitor.ts index 3973bd01c..badbae6dc 100644 --- a/server/src/db/models/monitors/Monitor.ts +++ b/server/src/db/models/monitors/Monitor.ts @@ -19,6 +19,13 @@ export const MonitorStatuses = [ ] as const; export type MonitorStatus = (typeof MonitorStatuses)[number]; +export interface IMonitorThresholds { + cpu?: number; + memory?: number; + disk?: number; + temperature?: number; +} + export interface IMonitor extends Document { _id: Types.ObjectId; orgId: Types.ObjectId; @@ -32,6 +39,7 @@ export interface IMonitor extends Document { rejectUnauthorized: boolean; status: MonitorStatus; n: number; // Number of consecutive successes required to change status + thresholds?: IMonitorThresholds; lastCheckedAt?: Date; latestChecks: { status: MonitorStatus; @@ -45,6 +53,16 @@ export interface IMonitor extends Document { updatedAt: Date; } +const ThresholdsSchema = new Schema( + { + cpu: { type: Number, min: 0, max: 100 }, + memory: { type: Number, min: 0, max: 100 }, + disk: { type: Number, min: 0, max: 100 }, + temperature: { type: Number, min: -50, max: 150 }, + }, + { _id: false } +); + const MonitorSchema = new Schema( { orgId: { type: Schema.Types.ObjectId, ref: "Org", required: true }, @@ -67,6 +85,7 @@ const MonitorSchema = new Schema( enum: MonitorStatuses, }, n: { type: Number, required: true, default: 1 }, + thresholds: { type: ThresholdsSchema, required: false, default: undefined }, lastCheckedAt: { type: Date }, latestChecks: { type: [ diff --git a/server/src/services/business/MonitorService.ts b/server/src/services/business/MonitorService.ts index b6e49e4a0..c4a41c2c3 100644 --- a/server/src/services/business/MonitorService.ts +++ b/server/src/services/business/MonitorService.ts @@ -646,6 +646,7 @@ class MonitorService implements IMonitorService { "rejectUnauthorized", "n", "notificationChannels", + "thresholds", ]; const safeUpdate: Partial = {}; diff --git a/server/src/validation/index.ts b/server/src/validation/index.ts index 39c011914..1c736cf23 100644 --- a/server/src/validation/index.ts +++ b/server/src/validation/index.ts @@ -62,6 +62,14 @@ export const monitorSchema = z secret: z.string().optional(), interval: z.number({ message: "Interval required" }), rejectUnauthorized: z.boolean().default(true), + thresholds: z + .object({ + cpu: z.number().min(0).max(100).optional(), + memory: z.number().min(0).max(100).optional(), + disk: z.number().min(0).max(100).optional(), + temperature: z.number().min(0).max(150).optional(), + }) + .optional(), }) .superRefine((data, ctx) => { const minIntervals: Record = {