uptime-kuma/server/notification-providers/goalert.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

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