fix DU operations

This commit is contained in:
Alex Holliday
2025-02-05 13:59:28 -08:00
parent b9bcc893b0
commit 85a5b83ab8
5 changed files with 51 additions and 1 deletions

View File

@@ -138,6 +138,7 @@ class DistributedUptimeController {
clearInterval(keepAlive);
});
} catch (error) {
console.log(error);
next(handleError(error, SERVICE_NAME, "getDistributedUptimeMonitors"));
}
}

View File

@@ -43,6 +43,11 @@ import * as hardwareCheckModule from "./modules/hardwareCheckModule.js";
import * as checkModule from "./modules/checkModule.js";
//****************************************
// Distributed Checks
//****************************************
import * as distributedCheckModule from "./modules/distributedCheckModule.js";
//****************************************
// Maintenance Window
//****************************************
@@ -74,6 +79,7 @@ class MongoDB {
Object.assign(this, pageSpeedCheckModule);
Object.assign(this, hardwareCheckModule);
Object.assign(this, checkModule);
Object.assign(this, distributedCheckModule);
Object.assign(this, maintenanceWindowModule);
Object.assign(this, notificationModule);
Object.assign(this, settingsModule);

View File

@@ -0,0 +1,15 @@
import DistributedUptimeCheck from "../../models/DistributedUptimeCheck.js";
const SERVICE_NAME = "distributedCheckModule";
const createDistributedCheck = async (checkData) => {
try {
const check = await new DistributedUptimeCheck({ ...checkData }).save();
return check;
} catch (error) {
error.service = SERVICE_NAME;
error.method = "createCheck";
throw error;
}
};
export { createDistributedCheck };

View File

@@ -674,6 +674,26 @@ const getMonitorsByTeamId = async (req) => {
},
]
: []),
...(limit
? [
{
$lookup: {
from: "distributeduptimechecks",
let: { monitorId: "$_id" },
pipeline: [
{
$match: {
$expr: { $eq: ["$monitorId", "$$monitorId"] },
},
},
{ $sort: { createdAt: -1 } },
...(limit ? [{ $limit: limit }] : []),
],
as: "distributeduptimechecks",
},
},
]
: []),
{
$addFields: {
@@ -692,6 +712,10 @@ const getMonitorsByTeamId = async (req) => {
case: { $eq: ["$type", "hardware"] },
then: "$hardwarechecks",
},
{
case: { $eq: ["$type", "distributed_http"] },
then: "$distributeduptimechecks",
},
],
default: [],
},

View File

@@ -244,7 +244,11 @@ const startApp = async () => {
ServiceRegistry.get(MongoDB.SERVICE_NAME)
);
const distributedUptimeController = new DistributedUptimeController();
const distributedUptimeController = new DistributedUptimeController(
ServiceRegistry.get(MongoDB.SERVICE_NAME),
http,
ServiceRegistry.get(StatusService.SERVICE_NAME)
);
//Create routes
const authRoutes = new AuthRoutes(authController);