From 988ba79679f7cfacb42453470982f4c465797eeb Mon Sep 17 00:00:00 2001 From: Ezhil Shanmugham Date: Tue, 30 Apr 2024 19:47:34 +0530 Subject: [PATCH] feat: keephq notification provider (#4722) --- server/notification-providers/keep.js | 42 +++++++++++++++++++++++++++ server/notification.js | 2 ++ src/components/NotificationDialog.vue | 1 + src/components/notifications/Keep.vue | 42 +++++++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ src/lang/en.json | 1 + 6 files changed, 90 insertions(+) create mode 100644 server/notification-providers/keep.js create mode 100644 src/components/notifications/Keep.vue diff --git a/server/notification-providers/keep.js b/server/notification-providers/keep.js new file mode 100644 index 000000000..aa65a867b --- /dev/null +++ b/server/notification-providers/keep.js @@ -0,0 +1,42 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Keep extends NotificationProvider { + name = "Keep"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let data = { + heartbeat: heartbeatJSON, + monitor: monitorJSON, + msg, + }; + let config = { + headers: { + "x-api-key": notification.webhookAPIKey, + "content-type": "application/json", + }, + }; + + let url = notification.webhookURL; + + if (url.endsWith("/")) { + url = url.slice(0, -1); + } + + let webhookURL = url + "/alerts/event/uptimekuma"; + + await axios.post(webhookURL, data, config); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Keep; diff --git a/server/notification.js b/server/notification.js index b64bb1b56..03bd368ed 100644 --- a/server/notification.js +++ b/server/notification.js @@ -18,6 +18,7 @@ const Gotify = require("./notification-providers/gotify"); const GrafanaOncall = require("./notification-providers/grafana-oncall"); const HomeAssistant = require("./notification-providers/home-assistant"); const HeiiOnCall = require("./notification-providers/heii-oncall"); +const Keep = require("./notification-providers/keep"); const Kook = require("./notification-providers/kook"); const Line = require("./notification-providers/line"); const LineNotify = require("./notification-providers/linenotify"); @@ -95,6 +96,7 @@ class Notification { new GrafanaOncall(), new HomeAssistant(), new HeiiOnCall(), + new Keep(), new Kook(), new Line(), new LineNotify(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 347fa2308..09646d599 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -123,6 +123,7 @@ export default { "GrafanaOncall": "Grafana Oncall", "HeiiOnCall": "Heii On-Call", "HomeAssistant": "Home Assistant", + "Keep": "Keep", "Kook": "Kook", "line": "LINE Messenger", "LineNotify": "LINE Notify", diff --git a/src/components/notifications/Keep.vue b/src/components/notifications/Keep.vue new file mode 100644 index 000000000..f0c856ee8 --- /dev/null +++ b/src/components/notifications/Keep.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 51107ac9f..52bebf83d 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -17,6 +17,7 @@ import GrafanaOncall from "./GrafanaOncall.vue"; import GtxMessaging from "./GtxMessaging.vue"; import HomeAssistant from "./HomeAssistant.vue"; import HeiiOnCall from "./HeiiOnCall.vue"; +import Keep from "./Keep.vue"; import Kook from "./Kook.vue"; import Line from "./Line.vue"; import LineNotify from "./LineNotify.vue"; @@ -82,6 +83,7 @@ const NotificationFormList = { "GrafanaOncall": GrafanaOncall, "HomeAssistant": HomeAssistant, "HeiiOnCall": HeiiOnCall, + "Keep": Keep, "Kook": Kook, "line": Line, "LineNotify": LineNotify, diff --git a/src/lang/en.json b/src/lang/en.json index 45e800d9e..d4a0997c2 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -63,6 +63,7 @@ "Friendly Name": "Friendly Name", "URL": "URL", "Hostname": "Hostname", + "Host URL": "Host URL", "locally configured mail transfer agent": "locally configured mail transfer agent", "Either enter the hostname of the server you want to connect to or localhost if you intend to use a locally configured mail transfer agent": "Either enter the hostname of the server you want to connect to or {localhost} if you intend to use a {local_mta}", "Port": "Port",