Server status update bug fixed, simplified email notification
This commit is contained in:
1 parent
c558577c8c
commit
f80936dd71
1 file changed
+29
-34
+29
-34
@@ -85,43 +85,38 @@ CheckSchema.pre("save", async function (next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check if there are any notifications
|
// Check if there are any notifications
|
||||||
if (notifications && notifications.length > 0) {
|
|
||||||
// Only send email if monitor status has changed
|
|
||||||
if (monitor.status !== this.status) {
|
|
||||||
const emailService = new EmailService();
|
|
||||||
|
|
||||||
if (monitor.status === true && this.status === false) {
|
// Only send email if monitor status has changed
|
||||||
// Notify users that the monitor is down
|
if (monitor.status !== this.status) {
|
||||||
for (const notification of notifications) {
|
const emailService = new EmailService();
|
||||||
if (notification.type === "email") {
|
|
||||||
await emailService.buildAndSendEmail(
|
|
||||||
"serverIsDownTemplate",
|
|
||||||
{ monitorName: monitor.name, monitorUrl: monitor.url },
|
|
||||||
notification.address,
|
|
||||||
`Monitor ${monitor.name} is down`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor.status === false && this.status === true) {
|
let template = "";
|
||||||
// Notify users that the monitor is up
|
let status = "";
|
||||||
for (const notification of notifications) {
|
if (monitor.status === true && this.status === false) {
|
||||||
if (notification.type === "email") {
|
template = "serverIsDownTemplate";
|
||||||
await emailService.buildAndSendEmail(
|
status = "down";
|
||||||
"serverIsUpTemplate",
|
|
||||||
{ monitorName: monitor.name, monitorUrl: monitor.url },
|
|
||||||
notification.address,
|
|
||||||
`Monitor ${monitor.name} is back up`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update monitor status
|
|
||||||
monitor.status = this.status;
|
|
||||||
await monitor.save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (monitor.status === false && this.status === true) {
|
||||||
|
// Notify users that the monitor is up
|
||||||
|
template = "serverIsUpTemplate";
|
||||||
|
status = "up";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const notification of notifications) {
|
||||||
|
if (notification.type === "email") {
|
||||||
|
await emailService.buildAndSendEmail(
|
||||||
|
template,
|
||||||
|
{ monitorName: monitor.name, monitorUrl: monitor.url },
|
||||||
|
notification.address,
|
||||||
|
`Monitor ${monitor.name} is ${status}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update monitor status
|
||||||
|
monitor.status = this.status;
|
||||||
|
await monitor.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in new issue
Block a user