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