2022-08-23 10:52:54 -07:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { UP } = require("../../src/util");
|
|
|
|
|
|
|
|
class GoAlert extends NotificationProvider {
|
2022-08-23 22:07:15 -07:00
|
|
|
name = "GoAlert";
|
2022-08-23 10:52:54 -07:00
|
|
|
|
2023-08-11 00:46:41 -07:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2022-08-23 10:52:54 -07:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 06:21:15 -07:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2022-08-23 10:52:54 -07:00
|
|
|
try {
|
2022-08-23 23:06:29 -07:00
|
|
|
let data = {
|
|
|
|
summary: msg,
|
|
|
|
};
|
|
|
|
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
2024-03-14 06:21:15 -07:00
|
|
|
data["action"] = "close";
|
2022-08-23 23:06:29 -07:00
|
|
|
}
|
|
|
|
let headers = {
|
2022-08-23 23:11:42 -07:00
|
|
|
"Content-Type": "multipart/form-data",
|
2022-08-23 23:06:29 -07:00
|
|
|
};
|
|
|
|
let config = {
|
|
|
|
headers: headers
|
|
|
|
};
|
2022-09-15 00:11:27 -07:00
|
|
|
await axios.post(`${notification.goAlertBaseURL}/api/v2/generic/incoming?token=${notification.goAlertToken}`, data, config);
|
2022-08-23 10:52:54 -07:00
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
let msg = (error.response.data) ? error.response.data : "Error without response";
|
|
|
|
throw new Error(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = GoAlert;
|