|
|
@ -1,5 +1,6 @@
|
|
|
|
const nodemailer = require("nodemailer");
|
|
|
|
const nodemailer = require("nodemailer");
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
|
|
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
|
|
|
|
|
|
|
|
class SMTP extends NotificationProvider {
|
|
|
|
class SMTP extends NotificationProvider {
|
|
|
|
|
|
|
|
|
|
|
@ -34,27 +35,23 @@ class SMTP extends NotificationProvider {
|
|
|
|
let replaceHostname = new RegExp("{HOSTNAME}", "g");
|
|
|
|
let replaceHostname = new RegExp("{HOSTNAME}", "g");
|
|
|
|
let replaceStatus = new RegExp("{STATUS}", "g");
|
|
|
|
let replaceStatus = new RegExp("{STATUS}", "g");
|
|
|
|
|
|
|
|
|
|
|
|
let serviceStatus;
|
|
|
|
// Lets start with dummy values to simplify code
|
|
|
|
|
|
|
|
let monitorName = "Test"
|
|
|
|
|
|
|
|
let monitorHostname = "example.com"
|
|
|
|
|
|
|
|
let serviceStatus = "⚠️ Test";
|
|
|
|
|
|
|
|
|
|
|
|
if (monitorJSON !== null) {
|
|
|
|
if (monitorJSON !== null) {
|
|
|
|
customsubject = customsubject.replace(replaceName,monitorJSON["name"]);
|
|
|
|
monitorName = monitorJSON["name"];
|
|
|
|
customsubject = customsubject.replace(replaceHostname,monitorJSON["hostname"]);
|
|
|
|
monitorHostname = monitorJSON["hostname"];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Insert dummy values during test
|
|
|
|
|
|
|
|
customsubject = customsubject.replace(replaceName,"Test");
|
|
|
|
|
|
|
|
customsubject = customsubject.replace(replaceHostname,"example.com");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (heartbeatJSON !== null) {
|
|
|
|
if (heartbeatJSON !== null) {
|
|
|
|
if (heartbeatJSON["status"] === 0) {
|
|
|
|
serviceStatus = heartbeatJSON["status"] == DOWN ? "🔴 Down":"✅ Up";
|
|
|
|
serviceStatus = "🔴 Down"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
serviceStatus = "✅ Up"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break replace to one by line for better readability
|
|
|
|
customsubject = customsubject.replace(replaceStatus,serviceStatus);
|
|
|
|
customsubject = customsubject.replace(replaceStatus,serviceStatus);
|
|
|
|
} else {
|
|
|
|
customsubject = customsubject.replace(replaceName,monitorName);
|
|
|
|
// Insert dummy values during test
|
|
|
|
customsubject = customsubject.replace(replaceHostname,monitorHostname);
|
|
|
|
customsubject = customsubject.replace(replaceStatus,"TEST");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subject = customsubject
|
|
|
|
subject = customsubject
|
|
|
|
}
|
|
|
|
}
|
|
|
|