fix: also migrate threshold value of 0 to 100, fix formatting
Addresses review feedback — thresholds set to 0 also caused issues and should be migrated to 100 (disabled) alongside the value of 5.
This commit is contained in:
1 parent
93b9abd508
commit
8df263fd93
1 file changed
+8
-13
@@ -2,7 +2,7 @@ import { MonitorModel } from "../models/Monitor.js";
|
|||||||
import { logger } from "@/utils/logger.js";
|
import { logger } from "@/utils/logger.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix infrastructure monitors that had thresholds incorrectly set to 5
|
* Fix infrastructure monitors that had thresholds incorrectly set to 0 or 5
|
||||||
* due to the old default value. Updates them to 100 (disabled).
|
* due to the old default value. Updates them to 100 (disabled).
|
||||||
*/
|
*/
|
||||||
export async function fixInfrastructureThresholds(): Promise<void> {
|
export async function fixInfrastructureThresholds(): Promise<void> {
|
||||||
@@ -11,29 +11,24 @@ export async function fixInfrastructureThresholds(): Promise<void> {
|
|||||||
try {
|
try {
|
||||||
logger.info({ service: SERVICE_NAME, message: "Starting infrastructure threshold fix" });
|
logger.info({ service: SERVICE_NAME, message: "Starting infrastructure threshold fix" });
|
||||||
|
|
||||||
const thresholdFields = [
|
const thresholdFields = ["cpuAlertThreshold", "memoryAlertThreshold", "diskAlertThreshold", "tempAlertThreshold"];
|
||||||
"cpuAlertThreshold",
|
|
||||||
"memoryAlertThreshold",
|
|
||||||
"diskAlertThreshold",
|
|
||||||
"tempAlertThreshold",
|
|
||||||
];
|
|
||||||
|
|
||||||
// Find hardware monitors with any threshold set to 5
|
// Find hardware monitors with any threshold set to 0 or 5
|
||||||
const filter = {
|
const filter = {
|
||||||
type: "hardware",
|
type: "hardware",
|
||||||
$or: thresholdFields.map((field) => ({ [field]: 5 })),
|
$or: thresholdFields.flatMap((field) => [{ [field]: 0 }, { [field]: 5 }]),
|
||||||
};
|
};
|
||||||
|
|
||||||
const monitors = await MonitorModel.find(filter);
|
const monitors = await MonitorModel.find(filter);
|
||||||
|
|
||||||
if (monitors.length === 0) {
|
if (monitors.length === 0) {
|
||||||
logger.info({ service: SERVICE_NAME, message: "No monitors with threshold value of 5 found" });
|
logger.info({ service: SERVICE_NAME, message: "No monitors with threshold value of 0 or 5 found" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info({
|
logger.info({
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
message: `Found ${monitors.length} monitors with threshold value of 5`,
|
message: `Found ${monitors.length} monitors with threshold value of 0 or 5`,
|
||||||
});
|
});
|
||||||
|
|
||||||
let updatedCount = 0;
|
let updatedCount = 0;
|
||||||
@@ -42,7 +37,7 @@ export async function fixInfrastructureThresholds(): Promise<void> {
|
|||||||
const update: Record<string, number> = {};
|
const update: Record<string, number> = {};
|
||||||
|
|
||||||
for (const field of thresholdFields) {
|
for (const field of thresholdFields) {
|
||||||
if ((monitor as any)[field] === 5) {
|
if ((monitor as any)[field] === 0 || (monitor as any)[field] === 5) {
|
||||||
update[field] = 100;
|
update[field] = 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +50,7 @@ export async function fixInfrastructureThresholds(): Promise<void> {
|
|||||||
|
|
||||||
logger.info({
|
logger.info({
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
message: `Fixed ${updatedCount} monitors — thresholds updated from 5 to 100`,
|
message: `Fixed ${updatedCount} monitors — thresholds updated from 0/5 to 100`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||||
|
|||||||
Reference in new issue
Block a user