From 65e6921a41b709fbf344ed3c802b291cc292a1db Mon Sep 17 00:00:00 2001 From: Muhammed Hussein Karimi Date: Tue, 23 Aug 2022 22:22:54 +0430 Subject: [PATCH] goalert notification provider added --- server/notification-providers/goalert.js | 32 ++++++++++++++++++++++++ server/notification.js | 2 ++ 2 files changed, 34 insertions(+) create mode 100644 server/notification-providers/goalert.js diff --git a/server/notification-providers/goalert.js b/server/notification-providers/goalert.js new file mode 100644 index 000000000..9a63ca5b4 --- /dev/null +++ b/server/notification-providers/goalert.js @@ -0,0 +1,32 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { UP } = require("../../src/util"); + +class GoAlert extends NotificationProvider { + + name = "goalert"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + let closeAction = "close"; + let parameters = { + token: notification.goAlertToken, + summary: msg, + } + if (heartbeatJSON["status"] === UP) { + parameters["action"] = closeAction; + } + try { + await axios.get(`${notification.goAlertBaseURL}/api/v2/generic/incoming`, { + params: parameters, + }); + return okMsg; + + } catch (error) { + let msg = (error.response.data) ? error.response.data : "Error without response"; + throw new Error(msg); + } + } +} + +module.exports = GoAlert; diff --git a/server/notification.js b/server/notification.js index 8093572a1..e7afbdc9b 100644 --- a/server/notification.js +++ b/server/notification.js @@ -38,6 +38,7 @@ const TechulusPush = require("./notification-providers/techulus-push"); const Telegram = require("./notification-providers/telegram"); const Webhook = require("./notification-providers/webhook"); const WeCom = require("./notification-providers/wecom"); +const GoAlert = require("./notification-providers/goalert") class Notification { @@ -88,6 +89,7 @@ class Notification { new Telegram(), new Webhook(), new WeCom(), + new GoAlert(), ]; for (let item of list) {