2022-08-23 19:52:54 +02:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { UP } = require("../../src/util");
|
|
|
|
|
|
|
|
class GoAlert extends NotificationProvider {
|
|
|
|
|
2022-08-24 07:07:15 +02:00
|
|
|
name = "GoAlert";
|
2022-08-23 19:52:54 +02:00
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
let closeAction = "close";
|
|
|
|
let parameters = {
|
|
|
|
token: notification.goAlertToken,
|
|
|
|
summary: msg,
|
2022-08-23 19:56:20 +02:00
|
|
|
};
|
2022-08-24 07:07:15 +02:00
|
|
|
// if (heartbeatJSON["status"] === UP) {
|
|
|
|
// parameters["action"] = closeAction;
|
|
|
|
// }
|
2022-08-23 19:52:54 +02:00
|
|
|
try {
|
2022-08-24 06:16:20 +02:00
|
|
|
await axios.post(`${notification.goAlertBaseURL}/api/v2/generic/incoming`, {
|
2022-08-23 19:52:54 +02:00
|
|
|
params: parameters,
|
|
|
|
});
|
|
|
|
return okMsg;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
let msg = (error.response.data) ? error.response.data : "Error without response";
|
2022-08-24 07:07:15 +02:00
|
|
|
console.log(error)
|
2022-08-23 19:52:54 +02:00
|
|
|
throw new Error(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = GoAlert;
|