2022-06-11 15:02:44 -04:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { setting } = require("../util-server");
|
|
|
|
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
|
|
|
|
|
|
|
class AlertNow extends NotificationProvider {
|
|
|
|
name = "AlertNow";
|
|
|
|
|
2023-08-11 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-06-11 15:02:44 -04:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 09:21:15 -04:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2022-06-11 15:02:44 -04:00
|
|
|
try {
|
|
|
|
let textMsg = "";
|
|
|
|
let status = "open";
|
|
|
|
let eventType = "ERROR";
|
|
|
|
let eventId = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
|
|
|
|
|
|
|
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
|
|
|
textMsg = `[${heartbeatJSON.name}] ✅ Application is back online`;
|
|
|
|
status = "close";
|
|
|
|
eventType = "INFO";
|
|
|
|
eventId += `_${heartbeatJSON.name.replace(/\s/g, "")}`;
|
|
|
|
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
|
|
|
textMsg = `[${heartbeatJSON.name}] 🔴 Application went down`;
|
|
|
|
}
|
|
|
|
|
|
|
|
textMsg += ` - ${msg}`;
|
|
|
|
|
|
|
|
const baseURL = await setting("primaryBaseURL");
|
|
|
|
if (baseURL && monitorJSON) {
|
|
|
|
textMsg += ` >> ${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
"summary": textMsg,
|
|
|
|
"status": status,
|
|
|
|
"event_type": eventType,
|
|
|
|
"event_id": eventId,
|
|
|
|
};
|
|
|
|
|
|
|
|
await axios.post(notification.alertNowWebhookURL, data);
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AlertNow;
|