From 67849a9e843cbe61d5727b5585ee6b2a5c7e053e Mon Sep 17 00:00:00 2001 From: Jonas Liebert Date: Thu, 2 Dec 2021 08:53:45 +0100 Subject: [PATCH] add support for stackfield notifications --- server/notification-providers/stackfield.js | 41 +++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/Stackfield.vue | 13 +++++++ src/components/notifications/index.js | 2 + src/languages/en.js | 1 + 5 files changed, 59 insertions(+) create mode 100644 server/notification-providers/stackfield.js create mode 100644 src/components/notifications/Stackfield.vue diff --git a/server/notification-providers/stackfield.js b/server/notification-providers/stackfield.js new file mode 100644 index 00000000..7f22634e --- /dev/null +++ b/server/notification-providers/stackfield.js @@ -0,0 +1,41 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { setting } = require("../util-server"); +const { getMonitorRelativeURL } = require("../../src/util"); + +class Stackfield extends NotificationProvider { + + name = "stackfield"; + + async send(notification, msg, monitorJSON = null) { + let okMsg = "Sent Successfully."; + try { + // Stackfield message formatting: https://www.stackfield.com/help/formatting-messages-2001 + + let textMsg = "+Uptime Kuma Alert+"; + + if (monitorJSON && monitorJSON.name) { + textMsg += `\n*${monitorJSON.name}*`; + } + + textMsg += `\n${msg}`; + + const baseURL = await setting("primaryBaseURL"); + if (baseURL) { + textMsg += `\n${baseURL + getMonitorRelativeURL(monitorJSON.id)}`; + } + + const data = { + "Title": textMsg, + }; + + await axios.post(notification.stackfieldwebhookURL, data); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + + } +} + +module.exports = Stackfield; diff --git a/server/notification.js b/server/notification.js index e2cfb193..3eb5f97b 100644 --- a/server/notification.js +++ b/server/notification.js @@ -24,6 +24,7 @@ const AliyunSms = require("./notification-providers/aliyun-sms"); const DingDing = require("./notification-providers/dingding"); const Bark = require("./notification-providers/bark"); const SerwerSMS = require("./notification-providers/serwersms"); +const Stackfield = require("./notification-providers/stackfield"); class Notification { @@ -60,6 +61,7 @@ class Notification { new Webhook(), new Bark(), new SerwerSMS(), + new Stackfield(), ]; for (let item of list) { diff --git a/src/components/notifications/Stackfield.vue b/src/components/notifications/Stackfield.vue new file mode 100644 index 00000000..c8dfb72b --- /dev/null +++ b/src/components/notifications/Stackfield.vue @@ -0,0 +1,13 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index bb71fba0..155a1ab2 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -23,6 +23,7 @@ import AliyunSMS from "./AliyunSms.vue"; import DingDing from "./DingDing.vue"; import Bark from "./Bark.vue"; import SerwerSMS from "./SerwerSMS.vue"; +import Stackfield from './Stackfield.vue'; /** * Manage all notification form. @@ -55,6 +56,7 @@ const NotificationFormList = { "DingDing": DingDing, "Bark": Bark, "serwersms": SerwerSMS, + "stackfield": Stackfield, } export default NotificationFormList diff --git a/src/languages/en.js b/src/languages/en.js index a51469c0..fee80a76 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -351,4 +351,5 @@ export default { serwersmsAPIPassword: "API Password", serwersmsPhoneNumber: "Phone number", serwersmsSenderName: "SMS Sender Name (registered via customer portal)", + "stackfield": "Stackfield", };