From 2fb6cb0b6f3f614dc0fb1c860a84ca9364858676 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Sat, 14 Feb 2026 21:29:30 +0000 Subject: [PATCH] remove alertThreshold --- client/src/Hooks/useMonitorForm.ts | 8 ++-- client/src/Types/Monitor.ts | 1 - server/src/db/models/Monitor.ts | 47 ++----------------- .../monitors/MongoMonitorsRepository.ts | 2 - .../SuperSimpleQueueHelper.ts | 8 ++-- .../notificationProviders/utils.ts | 10 ++-- server/src/types/monitor.ts | 1 - 7 files changed, 17 insertions(+), 60 deletions(-) diff --git a/client/src/Hooks/useMonitorForm.ts b/client/src/Hooks/useMonitorForm.ts index 153cf9f19..633fcb5c9 100644 --- a/client/src/Hooks/useMonitorForm.ts +++ b/client/src/Hooks/useMonitorForm.ts @@ -83,10 +83,10 @@ export const useMonitorForm = ({ type: "hardware", url: data?.url || "", secret: data?.secret || "", - cpuAlertThreshold: data?.cpuAlertThreshold ?? 80, - memoryAlertThreshold: data?.memoryAlertThreshold ?? 80, - diskAlertThreshold: data?.diskAlertThreshold ?? 80, - tempAlertThreshold: data?.tempAlertThreshold ?? 80, + cpuAlertThreshold: data?.cpuAlertThreshold ?? 100, + memoryAlertThreshold: data?.memoryAlertThreshold ?? 100, + diskAlertThreshold: data?.diskAlertThreshold ?? 100, + tempAlertThreshold: data?.tempAlertThreshold ?? 100, selectedDisks: data?.selectedDisks || [], }; break; diff --git a/client/src/Types/Monitor.ts b/client/src/Types/Monitor.ts index 2f1c1838d..fdd66b671 100644 --- a/client/src/Types/Monitor.ts +++ b/client/src/Types/Monitor.ts @@ -46,7 +46,6 @@ export interface Monitor { uptimePercentage?: number; notifications: string[]; secret?: string; - alertThreshold: number; cpuAlertThreshold: number; memoryAlertThreshold: number; diskAlertThreshold: number; diff --git a/server/src/db/models/Monitor.ts b/server/src/db/models/Monitor.ts index bb3108ed3..673872fba 100644 --- a/server/src/db/models/Monitor.ts +++ b/server/src/db/models/Monitor.ts @@ -121,33 +121,21 @@ const MonitorSchema = new Schema( secret: { type: String, }, - alertThreshold: { - type: Number, - default: 5, - }, cpuAlertThreshold: { type: Number, - default: function () { - return this.alertThreshold; - }, + default: 100, }, memoryAlertThreshold: { type: Number, - default: function () { - return this.alertThreshold; - }, + default: 100, }, diskAlertThreshold: { type: Number, - default: function () { - return this.alertThreshold; - }, + default: 100, }, tempAlertThreshold: { type: Number, - default: function () { - return this.alertThreshold; - }, + default: 100, }, selectedDisks: { type: [String], @@ -175,33 +163,6 @@ const MonitorSchema = new Schema( } ); -MonitorSchema.pre("save", function (next) { - if (!this.cpuAlertThreshold || this.isModified("alertThreshold")) { - this.cpuAlertThreshold = this.alertThreshold; - } - if (!this.memoryAlertThreshold || this.isModified("alertThreshold")) { - this.memoryAlertThreshold = this.alertThreshold; - } - if (!this.diskAlertThreshold || this.isModified("alertThreshold")) { - this.diskAlertThreshold = this.alertThreshold; - } - if (!this.tempAlertThreshold || this.isModified("alertThreshold")) { - this.tempAlertThreshold = this.alertThreshold; - } - next(); -}); - -MonitorSchema.pre("findOneAndUpdate", function (next) { - const update = this.getUpdate() as UpdateQuery | null; - if (update && !Array.isArray(update) && update.alertThreshold !== undefined) { - update.cpuAlertThreshold = update.alertThreshold; - update.memoryAlertThreshold = update.alertThreshold; - update.diskAlertThreshold = update.alertThreshold; - update.tempAlertThreshold = update.alertThreshold; - } - next(); -}); - MonitorSchema.index({ teamId: 1, type: 1 }); const MonitorModel = model("Monitor", MonitorSchema); diff --git a/server/src/repositories/monitors/MongoMonitorsRepository.ts b/server/src/repositories/monitors/MongoMonitorsRepository.ts index 7390d0e0e..71d4a2a41 100644 --- a/server/src/repositories/monitors/MongoMonitorsRepository.ts +++ b/server/src/repositories/monitors/MongoMonitorsRepository.ts @@ -317,7 +317,6 @@ class MongoMonitorsRepository implements IMonitorsRepository { uptimePercentage: doc.uptimePercentage ?? undefined, notifications: notificationIds, secret: doc.secret ?? undefined, - alertThreshold: doc.alertThreshold, cpuAlertThreshold: doc.cpuAlertThreshold, memoryAlertThreshold: doc.memoryAlertThreshold, diskAlertThreshold: doc.diskAlertThreshold, @@ -369,7 +368,6 @@ class MongoMonitorsRepository implements IMonitorsRepository { uptimePercentage: doc.uptimePercentage ?? undefined, notifications: notificationIds, secret: doc.secret ?? undefined, - alertThreshold: doc.alertThreshold, cpuAlertThreshold: doc.cpuAlertThreshold, memoryAlertThreshold: doc.memoryAlertThreshold, diskAlertThreshold: doc.diskAlertThreshold, diff --git a/server/src/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.ts b/server/src/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.ts index 0b143450c..85e54f793 100644 --- a/server/src/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.ts +++ b/server/src/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.ts @@ -269,10 +269,10 @@ class SuperSimpleQueueHelper { // Check if countdown has reached zero for any threshold const shouldNotifyThreshold = - (breaches.cpu && (monitor.cpuAlertThreshold ?? monitor.alertThreshold) <= 0) || - (breaches.memory && (monitor.memoryAlertThreshold ?? monitor.alertThreshold) <= 0) || - (breaches.disk && (monitor.diskAlertThreshold ?? monitor.alertThreshold) <= 0) || - (breaches.temp && (monitor.tempAlertThreshold ?? monitor.alertThreshold) <= 0); + (breaches.cpu && (monitor.cpuAlertThreshold ?? 100) <= 0) || + (breaches.memory && (monitor.memoryAlertThreshold ?? 100) <= 0) || + (breaches.disk && (monitor.diskAlertThreshold ?? 100) <= 0) || + (breaches.temp && (monitor.tempAlertThreshold ?? 100) <= 0); // Decision logic for hardware if (statusChanged && monitor.status === "down") { diff --git a/server/src/service/infrastructure/notificationProviders/utils.ts b/server/src/service/infrastructure/notificationProviders/utils.ts index ac964d93f..284855846 100644 --- a/server/src/service/infrastructure/notificationProviders/utils.ts +++ b/server/src/service/infrastructure/notificationProviders/utils.ts @@ -88,12 +88,12 @@ export const buildHardwareAlerts = ( const thresholdKey = alertThresholdKeyMap[type]; // Iterate over each alert type to see if any need to be decremented if (alerts[type] === true) { - const nextValue = ((monitor[thresholdKey] ?? monitor.alertThreshold) as number) - 1; + const nextValue = ((monitor[thresholdKey] ?? 100) as number) - 1; monitor[thresholdKey] = nextValue; // Decrement threshold if an alert is triggered if (monitor[thresholdKey] <= 0) { // If threshold drops below 0, reset and send notification - monitor[thresholdKey] = monitor.alertThreshold; + monitor[thresholdKey] = 100; const formatAlert = { cpu: () => `Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`, @@ -136,17 +136,17 @@ export const shouldSendHardwareAlert = (monitor: Monitor, networkResponse: Monit const { cpu: { usage_percent: cpuUsage = -1 } = {}, memory: { usage_percent: memoryUsage = -1 } = {}, disk = [] } = metrics; const cpuBreach = cpuThreshold !== -1 && cpuUsage > cpuThreshold; - if (cpuBreach && ((monitor.cpuAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) { + if (cpuBreach && ((monitor.cpuAlertThreshold ?? 100) as number) - 1 <= 0) { return true; } const memoryBreach = memoryThreshold !== -1 && memoryUsage > memoryThreshold; - if (memoryBreach && ((monitor.memoryAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) { + if (memoryBreach && ((monitor.memoryAlertThreshold ?? 100) as number) - 1 <= 0) { return true; } const diskBreach = disk?.some((d) => diskThreshold !== -1 && typeof d?.usage_percent === "number" && d?.usage_percent > diskThreshold); - if (diskBreach && ((monitor.diskAlertThreshold ?? monitor.alertThreshold) as number) - 1 <= 0) { + if (diskBreach && ((monitor.diskAlertThreshold ?? 100) as number) - 1 <= 0) { return true; } diff --git a/server/src/types/monitor.ts b/server/src/types/monitor.ts index 83a207e2d..d92b351a9 100644 --- a/server/src/types/monitor.ts +++ b/server/src/types/monitor.ts @@ -32,7 +32,6 @@ export interface Monitor { uptimePercentage?: number; notifications: string[]; secret?: string; - alertThreshold: number; cpuAlertThreshold: number; memoryAlertThreshold: number; diskAlertThreshold: number;