From 4157c7d5463a7467c849dd71fd2d17b846b81c95 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 26 Sep 2022 22:16:34 +1300 Subject: [PATCH] Add support for Squadcast incoming webhook --- server/notification-providers/squadcast.js | 76 ++++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/Squadcast.vue | 6 ++ src/components/notifications/index.js | 2 + src/languages/en.js | 1 + 5 files changed, 87 insertions(+) create mode 100644 server/notification-providers/squadcast.js create mode 100644 src/components/notifications/Squadcast.vue diff --git a/server/notification-providers/squadcast.js b/server/notification-providers/squadcast.js new file mode 100644 index 00000000..0302cb6f --- /dev/null +++ b/server/notification-providers/squadcast.js @@ -0,0 +1,76 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class Squadcast extends NotificationProvider { + + name = "squadcast"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + + let config = {}; + let data = { + message: msg, + description: '', + tags: {}, + heartbeat: heartbeatJSON, + source: 'uptime-kuma' + } + + if (heartbeatJSON !== null) { + data.description = heartbeatJSON["msg"]; + data.event_id = heartbeatJSON["monitorID"]; + + if (heartbeatJSON["status"] === DOWN) { + data.message = `${monitorJSON['name']} is DOWN`; + data.status = "trigger"; + } else { + data.message = `${monitorJSON['name']} is UP`; + data.status = "resolve"; + } + + let address; + switch (monitorJSON["type"]) { + case "ping": + address = monitorJSON["hostname"]; + break; + case "port": + case "dns": + case "steam": + address = monitorJSON["hostname"]; + if (monitorJSON["port"]) { + address += ":" + monitorJSON["port"]; + } + break; + default: + address = monitorJSON["url"]; + break; + } + + data.tags["AlertAddress"] = address; + + monitorJSON["tags"].forEach(tag => { + data.tags[tag["name"]] = { + value: tag["value"] + }; + if (tag["color"] !== null) { + data.tags[tag["name"]]["color"] = tag["color"] + } + }); + } + + await axios.post(notification.squadcastWebhookURL, data, config); + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + + } + +} + +module.exports = Squadcast; \ No newline at end of file diff --git a/server/notification.js b/server/notification.js index 3bf51243..7a4b4f29 100644 --- a/server/notification.js +++ b/server/notification.js @@ -32,6 +32,7 @@ const SerwerSMS = require("./notification-providers/serwersms"); const Signal = require("./notification-providers/signal"); const Slack = require("./notification-providers/slack"); const SMTP = require("./notification-providers/smtp"); +const Squadcast = require("./notification-providers/squadcast"); const Stackfield = require("./notification-providers/stackfield"); const Teams = require("./notification-providers/teams"); const TechulusPush = require("./notification-providers/techulus-push"); @@ -87,6 +88,7 @@ class Notification { new SMSManager(), new Slack(), new SMTP(), + new Squadcast(), new Stackfield(), new Teams(), new TechulusPush(), diff --git a/src/components/notifications/Squadcast.vue b/src/components/notifications/Squadcast.vue new file mode 100644 index 00000000..6650c44d --- /dev/null +++ b/src/components/notifications/Squadcast.vue @@ -0,0 +1,6 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 6add06ea..319a7922 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -31,6 +31,7 @@ import SerwerSMS from "./SerwerSMS.vue"; import Signal from "./Signal.vue"; import SMSManager from "./SMSManager.vue"; import Slack from "./Slack.vue"; +import Squadcast from "./Squadcast.vue"; import Stackfield from "./Stackfield.vue"; import STMP from "./SMTP.vue"; import Teams from "./Teams.vue"; @@ -79,6 +80,7 @@ const NotificationFormList = { "signal": Signal, "SMSManager": SMSManager, "slack": Slack, + "squadcast": Squadcast, "smtp": STMP, "stackfield": Stackfield, "teams": Teams, diff --git a/src/languages/en.js b/src/languages/en.js index 7d980f63..1f20c7ea 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -582,4 +582,5 @@ export default { goAlert: "GoAlert", backupOutdatedWarning: "Deprecated: Since a lot of features added and this backup feature is a bit unmaintained, it cannot generate or restore a complete backup.", backupRecommend: "Please backup the volume or the data folder (./data/) directly instead.", + squadcast: "Squadcast", };