2024-02-12 18:58:54 -05:00
|
|
|
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
|
|
|
|
const { setting } = require("../util-server");
|
|
|
|
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
class HeiiOnCall extends NotificationProvider {
|
|
|
|
name = "HeiiOnCall";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-02-14 17:41:35 -05:00
|
|
|
const okMsg = "Sent Successfully.";
|
2024-02-13 19:54:52 -05:00
|
|
|
const payload = heartbeatJSON || {};
|
2024-02-12 18:58:54 -05:00
|
|
|
|
|
|
|
const baseURL = await setting("primaryBaseURL");
|
|
|
|
if (baseURL && monitorJSON) {
|
|
|
|
payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
|
|
|
}
|
|
|
|
|
2024-02-14 17:41:35 -05:00
|
|
|
const config = {
|
|
|
|
headers: {
|
|
|
|
Accept: "application/json",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
Authorization: "Bearer " + notification.heiiOnCallApiKey,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const heiiUrl = `https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/`;
|
|
|
|
// docs https://heiioncall.com/docs#manual-triggers
|
2024-02-13 20:27:59 -05:00
|
|
|
try {
|
|
|
|
if (!heartbeatJSON) {
|
|
|
|
// Testing or general notification like certificate expiry
|
|
|
|
payload["msg"] = msg;
|
2024-02-14 17:41:35 -05:00
|
|
|
await axios.post(heiiUrl + "alert", payload, config);
|
|
|
|
return okMsg;
|
2024-02-13 20:27:59 -05:00
|
|
|
}
|
2024-02-12 20:54:36 -05:00
|
|
|
|
2024-02-13 20:27:59 -05:00
|
|
|
if (heartbeatJSON.status === DOWN) {
|
2024-02-14 17:41:35 -05:00
|
|
|
await axios.post(heiiUrl + "alert", payload, config);
|
|
|
|
return okMsg;
|
2024-02-13 20:27:59 -05:00
|
|
|
}
|
|
|
|
if (heartbeatJSON.status === UP) {
|
2024-02-14 17:45:23 -05:00
|
|
|
await axios.post(heiiUrl + "resolve", payload, config);
|
2024-02-14 17:41:35 -05:00
|
|
|
return okMsg;
|
2024-02-13 20:27:59 -05:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
2024-02-12 18:58:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = HeiiOnCall;
|