From 34da8e271ad3d0b7086c1302a4251e66e18e6902 Mon Sep 17 00:00:00 2001 From: Joschua Becker Date: Tue, 12 Dec 2023 04:55:35 +0000 Subject: [PATCH 1/8] added: sevenio notification handler --- server/notification-providers/sevenio.js | 78 ++++++++++++++++++++++++ server/notification.js | 4 +- src/components/NotificationDialog.vue | 3 +- src/components/notifications/SevenIO.vue | 22 +++++++ src/components/notifications/index.js | 4 +- src/lang/en.json | 7 ++- 6 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 server/notification-providers/sevenio.js create mode 100644 src/components/notifications/SevenIO.vue diff --git a/server/notification-providers/sevenio.js b/server/notification-providers/sevenio.js new file mode 100644 index 00000000..675093db --- /dev/null +++ b/server/notification-providers/sevenio.js @@ -0,0 +1,78 @@ +const NotificationProvider = require("./notification-provider"); +const Axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class SevenIO extends NotificationProvider { + + name = "SevenIO"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + const data = { + to: notification.sevenioTo, + from: notification.sevenioSender || "Uptime Kuma", + text: msg, + }; + + const axios = Axios.create({ + baseURL: "https://gateway.seven.io/api/", + headers: { + "Content-Type": "application/json", + "X-API-Key": notification.sevenioApiKey, + }, + }); + + try { + // If heartbeatJSON is null, assume we're testing. + if (heartbeatJSON == null) { + await axios.post("sms", data); + return okMsg; + } + + let address; + + switch (monitorJSON["type"]) { + case "ping": + address = monitorJSON["hostname"]; + break; + case "port": + case "dns": + case "gamedig": + case "steam": + address = monitorJSON["hostname"]; + if (monitorJSON["port"]) { + address += ":" + monitorJSON["port"]; + } + break; + default: + address = monitorJSON["url"]; + break; + } + + // If heartbeatJSON is not null, we go into the normal alerting loop. + if (heartbeatJSON["status"] === DOWN) { + data.text = `Your service ${monitorJSON["name"]} (${address}) went down at ${heartbeatJSON["localDateTime"]} ` + + `(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`; + + await axios.post("sms", data); + return okMsg; + + } else if (heartbeatJSON["status"] === UP) { + data.text = `Your service ${monitorJSON["name"]} (${address}) went back up at ${heartbeatJSON["localDateTime"]} ` + + `(${heartbeatJSON["timezone"]}).`; + + await axios.post("sms", data); + return okMsg; + } + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + +} + +module.exports = SevenIO; diff --git a/server/notification.js b/server/notification.js index 5e76d6eb..591c8038 100644 --- a/server/notification.js +++ b/server/notification.js @@ -54,6 +54,7 @@ const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); const ServerChan = require("./notification-providers/serverchan"); const ZohoCliq = require("./notification-providers/zoho-cliq"); +const SevenIO = require("./notification-providers/sevenio"); class Notification { @@ -124,7 +125,8 @@ class Notification { new Webhook(), new WeCom(), new GoAlert(), - new ZohoCliq() + new ZohoCliq(), + new SevenIO(), ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 57a2fdf2..c795251f 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -151,7 +151,8 @@ export default { "Splunk": "Splunk", "webhook": "Webhook", "GoAlert": "GoAlert", - "ZohoCliq": "ZohoCliq" + "ZohoCliq": "ZohoCliq", + "SevenIO": "SevenIO", }; // Put notifications here if it's not supported in most regions or its documentation is not in English diff --git a/src/components/notifications/SevenIO.vue b/src/components/notifications/SevenIO.vue new file mode 100644 index 00000000..f79bc0bd --- /dev/null +++ b/src/components/notifications/SevenIO.vue @@ -0,0 +1,22 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 0606d41a..3c413a7d 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -52,6 +52,7 @@ import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; import ZohoCliq from "./ZohoCliq.vue"; import Splunk from "./Splunk.vue"; +import SevenIO from "./SevenIO.vue"; /** * Manage all notification form. @@ -111,7 +112,8 @@ const NotificationFormList = { "WeCom": WeCom, "GoAlert": GoAlert, "ServerChan": ServerChan, - "ZohoCliq": ZohoCliq + "ZohoCliq": ZohoCliq, + "SevenIO": SevenIO, }; export default NotificationFormList; diff --git a/src/lang/en.json b/src/lang/en.json index 50c2bb63..7d3bd962 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -880,5 +880,10 @@ "useRemoteBrowser": "Use a Remote Browser", "deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?", "GrafanaOncallUrl": "Grafana Oncall URL", - "Browser Screenshot": "Browser Screenshot" + "Browser Screenshot": "Browser Screenshot", + "wayToGetSevenIOApiKey": "Visit the dashboard under app.seven.io > developer > api key > the green add button", + "senderSevenIO": "Sending number or name", + "receiverSevenIO": "Receiving number", + "receiverInfoSevenIO": "If receiving number is not located in germany you have to add the country code in front of the number, eg: 4917612121212", + "apiKeySevenIO": "SevenIO API Key" } From 7904db89854640a91377a44e92b55166cb4ba590 Mon Sep 17 00:00:00 2001 From: Joschua Becker Date: Tue, 12 Dec 2023 06:08:50 +0100 Subject: [PATCH 2/8] fix: wrong naming for input field ids --- src/components/notifications/SevenIO.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/notifications/SevenIO.vue b/src/components/notifications/SevenIO.vue index f79bc0bd..ddea360e 100644 --- a/src/components/notifications/SevenIO.vue +++ b/src/components/notifications/SevenIO.vue @@ -1,20 +1,20 @@