fix: add migration to reset infrastructure thresholds from 5 to 100
## Changes - Added migration 0004_fixInfrastructureThresholds that finds hardware monitors with threshold values of 5 (the old incorrect default) and updates them to 100 (effectively disabled) - Runs automatically on server startup like other migrations ## Closes Fixes #3327
This commit is contained in:
1 parent
189293b04d
commit
93b9abd508
2 files changed
+67
No files matched your search
@@ -0,0 +1,65 @@
|
|||||||
|
import { MonitorModel } from "../models/Monitor.js";
|
||||||
|
import { logger } from "@/utils/logger.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix infrastructure monitors that had thresholds incorrectly set to 5
|
||||||
|
* due to the old default value. Updates them to 100 (disabled).
|
||||||
|
*/
|
||||||
|
export async function fixInfrastructureThresholds(): Promise<void> {
|
||||||
|
const SERVICE_NAME = "Migration:FixInfrastructureThresholds";
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info({ service: SERVICE_NAME, message: "Starting infrastructure threshold fix" });
|
||||||
|
|
||||||
|
const thresholdFields = [
|
||||||
|
"cpuAlertThreshold",
|
||||||
|
"memoryAlertThreshold",
|
||||||
|
"diskAlertThreshold",
|
||||||
|
"tempAlertThreshold",
|
||||||
|
];
|
||||||
|
|
||||||
|
// Find hardware monitors with any threshold set to 5
|
||||||
|
const filter = {
|
||||||
|
type: "hardware",
|
||||||
|
$or: thresholdFields.map((field) => ({ [field]: 5 })),
|
||||||
|
};
|
||||||
|
|
||||||
|
const monitors = await MonitorModel.find(filter);
|
||||||
|
|
||||||
|
if (monitors.length === 0) {
|
||||||
|
logger.info({ service: SERVICE_NAME, message: "No monitors with threshold value of 5 found" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info({
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
message: `Found ${monitors.length} monitors with threshold value of 5`,
|
||||||
|
});
|
||||||
|
|
||||||
|
let updatedCount = 0;
|
||||||
|
|
||||||
|
for (const monitor of monitors) {
|
||||||
|
const update: Record<string, number> = {};
|
||||||
|
|
||||||
|
for (const field of thresholdFields) {
|
||||||
|
if ((monitor as any)[field] === 5) {
|
||||||
|
update[field] = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(update).length > 0) {
|
||||||
|
await MonitorModel.updateOne({ _id: monitor._id }, { $set: update });
|
||||||
|
updatedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info({
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
message: `Fixed ${updatedCount} monitors — thresholds updated from 5 to 100`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
logger.error({ service: SERVICE_NAME, message: `Error fixing thresholds: ${errorMessage}` });
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js";
|
import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshold.js";
|
||||||
import { convertChecksToTimeSeries } from "./0002_convertChecksToTimeSeries.js";
|
import { convertChecksToTimeSeries } from "./0002_convertChecksToTimeSeries.js";
|
||||||
import { cleanupDuplicateMonitorStats } from "./0003_cleanupDuplicateMonitorStats.js";
|
import { cleanupDuplicateMonitorStats } from "./0003_cleanupDuplicateMonitorStats.js";
|
||||||
|
import { fixInfrastructureThresholds } from "./0004_fixInfrastructureThresholds.js";
|
||||||
import MigrationModel from "../models/Migration.js";
|
import MigrationModel from "../models/Migration.js";
|
||||||
|
|
||||||
type MigrationEntry = {
|
type MigrationEntry = {
|
||||||
@@ -12,6 +13,7 @@ const migrations: MigrationEntry[] = [
|
|||||||
{ name: "0001_migrateStatusWindowThreshold", execute: migrateStatusWindowThreshold },
|
{ name: "0001_migrateStatusWindowThreshold", execute: migrateStatusWindowThreshold },
|
||||||
{ name: "0002_convertChecksToTimeSeries", execute: convertChecksToTimeSeries },
|
{ name: "0002_convertChecksToTimeSeries", execute: convertChecksToTimeSeries },
|
||||||
{ name: "0003_cleanupDuplicateMonitorStats", execute: cleanupDuplicateMonitorStats },
|
{ name: "0003_cleanupDuplicateMonitorStats", execute: cleanupDuplicateMonitorStats },
|
||||||
|
{ name: "0004_fixInfrastructureThresholds", execute: fixInfrastructureThresholds },
|
||||||
];
|
];
|
||||||
|
|
||||||
const runMigrations = async (logger?: { info: Function; error: Function }) => {
|
const runMigrations = async (logger?: { info: Function; error: Function }) => {
|
||||||
|
|||||||
Reference in new issue
Block a user