From 73c9e27b707e9e3ebad222dbf4193cbc6ac0a637 Mon Sep 17 00:00:00 2001 From: vapao Date: Wed, 30 Apr 2025 17:39:10 +0800 Subject: [PATCH] Add SpugPush notification provider --- server/notification-providers/spugpush.js | 45 +++++++++++++++++++++++ server/notification.js | 2 + src/components/NotificationDialog.vue | 2 +- src/components/notifications/SpugPush.vue | 19 ++++++++++ src/components/notifications/index.js | 2 + src/lang/zh-CN.json | 1 + src/lang/zh-HK.json | 1 + src/lang/zh-TW.json | 1 + 8 files changed, 72 insertions(+), 1 deletion(-) 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..a0c2ec37d --- /dev/null +++ b/server/notification-providers/spugpush.js @@ -0,0 +1,45 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class SpugPush extends NotificationProvider { + + name = "SpugPush"; + + 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..7f479bb19 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -184,7 +184,7 @@ export default { "SMSManager": "SmsManager (smsmanager.cz)", "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..ff45071d8 --- /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/zh-CN.json b/src/lang/zh-CN.json index 88134e3d8..c6c4ea9d2 100644 --- a/src/lang/zh-CN.json +++ b/src/lang/zh-CN.json @@ -824,6 +824,7 @@ "Enable Kafka Producer Auto Topic Creation": "启用 Kafka 生成者(Producer)自动创建主题(Topic)功能", "Enable Kafka SSL": "启用 Kafka SSL 功能", "Kafka Producer Message": "Kafka 生成者(Producer)消息", + "SpugPush Template Key": "模板编码", "tailscalePingWarning": "如需使用 Tailscale Ping 客户端,您需要以非 docker 方式安装 Uptime Kuma,并同时安装 Tailscale 客户端。", "Server URL should not contain the nfty topic": "服务器地址不应包含 ntfy主题", "Select": "选择", diff --git a/src/lang/zh-HK.json b/src/lang/zh-HK.json index 9ecd5dd3a..64e30c1df 100644 --- a/src/lang/zh-HK.json +++ b/src/lang/zh-HK.json @@ -1076,6 +1076,7 @@ "Conditions": "條件", "Kafka Topic Name": "Kafka 主題名稱", "Kafka Producer Message": "Kafka 生成者(Producer)消息", + "SpugPush Template Key": "模板編碼", "Mechanism": "鑒權方式", "toastSuccessTimeout": "成功類彈窗通知的自動關閉用時", "pushoverMessageTtl": "消息存活時間(秒)", diff --git a/src/lang/zh-TW.json b/src/lang/zh-TW.json index b894f1298..f5b90eeec 100644 --- a/src/lang/zh-TW.json +++ b/src/lang/zh-TW.json @@ -821,6 +821,7 @@ "Enable Kafka SSL": "啟用 Kafka SSL", "Enable Kafka Producer Auto Topic Creation": "啟用 Kafka Producer 自動主題建立", "Kafka SASL Options": "Kafka SASL 選項", + "SpugPush Template Key": "模板編碼", "Mechanism": "機制", "gamedigGuessPortDescription": "Valve 伺服器查詢協定使用的連接埠可能與客戶端連接埠不同。如果監控無法連線到您的伺服器,請嘗試此選項。", "Saved.": "已儲存。",