From 716832b9f3ecc6763a70e5c1ef970e49cf3225f9 Mon Sep 17 00:00:00 2001 From: Ron <43244104+rons4@users.noreply.github.com> Date: Wed, 28 Aug 2024 23:18:25 +0200 Subject: [PATCH] New Notification Provider SIGNL4 (#5058) Co-authored-by: Frank Elsinga --- server/notification-providers/signl4.js | 52 +++++++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/SIGNL4.vue | 16 ++++++++ src/components/notifications/index.js | 2 + src/lang/en.json | 5 ++- 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/signl4.js create mode 100644 src/components/notifications/SIGNL4.vue diff --git a/server/notification-providers/signl4.js b/server/notification-providers/signl4.js new file mode 100644 index 000000000..e48983f59 --- /dev/null +++ b/server/notification-providers/signl4.js @@ -0,0 +1,52 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { UP, DOWN } = require("../../src/util"); + +class SIGNL4 extends NotificationProvider { + name = "SIGNL4"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + let data = { + heartbeat: heartbeatJSON, + monitor: monitorJSON, + msg, + // Source system + "X-S4-SourceSystem": "UptimeKuma", + monitorUrl: this.extractAdress(monitorJSON), + }; + + const config = { + headers: { + "Content-Type": "application/json" + } + }; + + if (heartbeatJSON == null) { + // Test alert + data.title = "Uptime Kuma Alert"; + data.message = msg; + } else if (heartbeatJSON.status === UP) { + data.title = "Uptime Kuma Monitor ✅ Up"; + data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID; + data["X-S4-Status"] = "resolved"; + } else if (heartbeatJSON.status === DOWN) { + data.title = "Uptime Kuma Monitor 🔴 Down"; + data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID; + data["X-S4-Status"] = "new"; + } + + await axios.post(notification.webhookURL, data, config); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = SIGNL4; diff --git a/server/notification.js b/server/notification.js index 8fce5b90c..60eae4d73 100644 --- a/server/notification.js +++ b/server/notification.js @@ -42,6 +42,7 @@ const Pushy = require("./notification-providers/pushy"); const RocketChat = require("./notification-providers/rocket-chat"); const SerwerSMS = require("./notification-providers/serwersms"); const Signal = require("./notification-providers/signal"); +const SIGNL4 = require("./notification-providers/signl4"); const Slack = require("./notification-providers/slack"); const SMSPartner = require("./notification-providers/smspartner"); const SMSEagle = require("./notification-providers/smseagle"); @@ -127,6 +128,7 @@ class Notification { new ServerChan(), new SerwerSMS(), new Signal(), + new SIGNL4(), new SMSManager(), new SMSPartner(), new Slack(), diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index c7ae19231..864cbf5f4 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -145,6 +145,7 @@ export default { "pushy": "Pushy", "rocket.chat": "Rocket.Chat", "signal": "Signal", + "SIGNL4": "SIGNL4", "slack": "Slack", "squadcast": "SquadCast", "SMSEagle": "SMSEagle", diff --git a/src/components/notifications/SIGNL4.vue b/src/components/notifications/SIGNL4.vue new file mode 100644 index 000000000..eb0145587 --- /dev/null +++ b/src/components/notifications/SIGNL4.vue @@ -0,0 +1,16 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 5ed5e70b2..e5df6fe4e 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -64,6 +64,7 @@ import SevenIO from "./SevenIO.vue"; import Whapi from "./Whapi.vue"; import Cellsynt from "./Cellsynt.vue"; import WPush from "./WPush.vue"; +import SIGNL4 from "./SIGNL4.vue"; /** * Manage all notification form. @@ -114,6 +115,7 @@ const NotificationFormList = { "rocket.chat": RocketChat, "serwersms": SerwerSMS, "signal": Signal, + "SIGNL4": SIGNL4, "SMSManager": SMSManager, "SMSPartner": SMSPartner, "slack": Slack, diff --git a/src/lang/en.json b/src/lang/en.json index c2e960d40..a09f01627 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -991,5 +991,8 @@ "Go back to home page.": "Go back to home page.", "No tags found.": "No tags found.", "Lost connection to the socket server.": "Lost connection to the socket server.", - "Cannot connect to the socket server.": "Cannot connect to the socket server." + "Cannot connect to the socket server.": "Cannot connect to the socket server.", + "SIGNL4": "SIGNL4", + "SIGNL4 Webhook URL": "SIGNL4 Webhook URL", + "signl4Docs": "You can find more information about how to configure SIGNL4 and how to obtain the SIGNL4 webhook URL in the {0}." }