diff options
Diffstat (limited to 'server/notification-providers/goalert.js')
-rw-r--r-- | server/notification-providers/goalert.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/server/notification-providers/goalert.js b/server/notification-providers/goalert.js new file mode 100644 index 0000000..847c6a0 --- /dev/null +++ b/server/notification-providers/goalert.js @@ -0,0 +1,36 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { UP } = require("../../src/util"); + +class GoAlert extends NotificationProvider { + name = "GoAlert"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + 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 + }; + await axios.post(`${notification.goAlertBaseURL}/api/v2/generic/incoming?token=${notification.goAlertToken}`, data, config); + return okMsg; + } catch (error) { + let msg = (error.response.data) ? error.response.data : "Error without response"; + throw new Error(msg); + } + } +} + +module.exports = GoAlert; |