From fc8edf0618790cd25b5784ca50650f1a1e787a8e Mon Sep 17 00:00:00 2001 From: vapao Date: Thu, 1 May 2025 04:10:10 +0800 Subject: [PATCH] Add SpugPush notification provider --- server/notification-providers/spugpush.js | 48 +++++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 1 + src/components/notifications/SpugPush.vue | 19 +++++++++ src/components/notifications/index.js | 2 + src/lang/en.json | 1 + 6 files changed, 73 insertions(+) create mode 100644 server/notification-providers/spugpush.js create mode 100644 src/components/notifications/SpugPush.vue diff --git a/server/notification-providers/spugpush.js b/server/notification-providers/spugpush.js new file mode 100644 index 000000000..61574cab9 --- /dev/null +++ b/server/notification-providers/spugpush.js @@ -0,0 +1,48 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SpugPush extends NotificationProvider { + + name = "SpugPush"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + await axios.post(`https://push.spug.cc/send/${notification.templateKey}`, { + "status": heartbeatJSON["status"], + "msg": heartbeatJSON["msg"], + "duration": heartbeatJSON["duration"], + "name": monitorJSON["name"], + "target": this.getTarget(monitorJSON), + }); + + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + + /** + * Get the formatted target for message + * @param {object} monitorJSON Monitor details (For Up/Down only) + * @returns {string} Formatted target + */ + getTarget(monitorJSON) { + let target = "-"; + if (monitorJSON["hostname"]) { + target = monitorJSON["hostname"]; + if (monitorJSON["port"]) { + target += ":" + monitorJSON["port"]; + } + } else if (monitorJSON["url"]) { + target = monitorJSON["url"]; + } + return target; + } +} + +module.exports = SpugPush; diff --git a/server/notification.js b/server/notification.js index b3f745854..468d026c0 100644 --- a/server/notification.js +++ b/server/notification.js @@ -75,6 +75,7 @@ const Wpush = require("./notification-providers/wpush"); const SendGrid = require("./notification-providers/send-grid"); const YZJ = require("./notification-providers/yzj"); const SMSPlanet = require("./notification-providers/sms-planet"); +const SpugPush = require("./notification-providers/spugpush"); class Notification { @@ -167,6 +168,7 @@ class Notification { new SendGrid(), new YZJ(), new SMSPlanet(), + new SpugPush(), ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 1b15616aa..2e66de8e9 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -185,6 +185,7 @@ export default { "WeCom": "WeCom (企业微信群机器人)", "ServerChan": "ServerChan (Server酱)", "PushPlus": "PushPlus (推送加)", + "SpugPush": "SpugPush(Spug推送助手)", "smsc": "SMSC", "WPush": "WPush(wpush.cn)", "YZJ": "YZJ (云之家自定义机器人)", diff --git a/src/components/notifications/SpugPush.vue b/src/components/notifications/SpugPush.vue new file mode 100644 index 000000000..37dffccf3 --- /dev/null +++ b/src/components/notifications/SpugPush.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 70e7d336d..be7feb820 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -64,6 +64,7 @@ import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; import ZohoCliq from "./ZohoCliq.vue"; import Splunk from "./Splunk.vue"; +import SpugPush from "./SpugPush.vue"; import SevenIO from "./SevenIO.vue"; import Whapi from "./Whapi.vue"; import WAHA from "./WAHA.vue"; @@ -140,6 +141,7 @@ const NotificationFormList = { "threema": Threema, "twilio": Twilio, "Splunk": Splunk, + "SpugPush": SpugPush, "webhook": Webhook, "WeCom": WeCom, "GoAlert": GoAlert, diff --git a/src/lang/en.json b/src/lang/en.json index b089478f8..caf29856b 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -798,6 +798,7 @@ "PushDeer Server": "PushDeer Server", "pushDeerServerDescription": "Leave blank to use the official server", "PushDeer Key": "PushDeer Key", + "SpugPush Template Code": "Template Code", "wayToGetClickSendSMSToken": "You can get API Username and API Key from {0} .", "Custom Monitor Type": "Custom Monitor Type", "Google Analytics ID": "Google Analytics ID",