From 3e212a5d7359529614c7e3a927e764f6c11950ef Mon Sep 17 00:00:00 2001 From: Alone88 Date: Wed, 20 Mar 2024 10:57:11 +0000 Subject: [PATCH 1/6] Add WPush Notification Provider --- server/notification-providers/wpush.js | 50 ++++++++++++++++++++++++++ server/notification.js | 4 ++- src/components/NotificationDialog.vue | 1 + src/components/notifications/WPush.vue | 31 ++++++++++++++++ src/components/notifications/index.js | 4 ++- 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 server/notification-providers/wpush.js create mode 100644 src/components/notifications/WPush.vue diff --git a/server/notification-providers/wpush.js b/server/notification-providers/wpush.js new file mode 100644 index 00000000..9b60365d --- /dev/null +++ b/server/notification-providers/wpush.js @@ -0,0 +1,50 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class WPush extends NotificationProvider { + name = "WPush"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + + try { + const ret = await axios.post("https://api.wpush.cn/api/v1/send", { + "title": this.checkStatus(heartbeatJSON, monitorJSON), + "content": msg, + "apikey": notification.wpushAPIkey, + "channel": notification.wpushChannel + }); + if (ret.data.code !== 0) { + return ret.data.message; + } + + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + + /** + * Get the formatted title for message + * @param {?object} heartbeatJSON Heartbeat details (For Up/Down only) + * @param {?object} monitorJSON Monitor details (For Up/Down only) + * @returns {string} Formatted title + */ + checkStatus(heartbeatJSON, monitorJSON) { + let title = "UptimeKuma Message"; + if (heartbeatJSON != null && heartbeatJSON["status"] === UP) { + title = "UptimeKuma Monitor Up " + monitorJSON["name"]; + } + if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) { + title = "UptimeKuma Monitor Down " + monitorJSON["name"]; + } + return title; + } +} + +module.exports = WPush; diff --git a/server/notification.js b/server/notification.js index 5a412c6e..81f9c337 100644 --- a/server/notification.js +++ b/server/notification.js @@ -55,6 +55,7 @@ const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); const ServerChan = require("./notification-providers/serverchan"); const ZohoCliq = require("./notification-providers/zoho-cliq"); +const WPush = require("./notification-providers/wpush"); class Notification { @@ -126,7 +127,8 @@ class Notification { new Webhook(), new WeCom(), new GoAlert(), - new ZohoCliq() + new ZohoCliq(), + new WPush(), ]; for (let item of list) { if (! item.name) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 56580fbf..f5eac3bf 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -169,6 +169,7 @@ export default { "WeCom": "WeCom (企业微信群机器人)", "ServerChan": "ServerChan (Server酱)", "smsc": "SMSC", + "WPush": "WPush(wpush.cn)", }; // Sort by notification name diff --git a/src/components/notifications/WPush.vue b/src/components/notifications/WPush.vue new file mode 100644 index 00000000..fa8f3e15 --- /dev/null +++ b/src/components/notifications/WPush.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 6cb0c9fd..f3b7ef18 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -53,6 +53,7 @@ import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; import ZohoCliq from "./ZohoCliq.vue"; import Splunk from "./Splunk.vue"; +import WPush from "./WPush.vue"; /** * Manage all notification form. @@ -113,7 +114,8 @@ const NotificationFormList = { "WeCom": WeCom, "GoAlert": GoAlert, "ServerChan": ServerChan, - "ZohoCliq": ZohoCliq + "ZohoCliq": ZohoCliq, + "WPush": WPush }; export default NotificationFormList; From 31d459c342f5b48c68f8f197925b24af3c9d5d94 Mon Sep 17 00:00:00 2001 From: Alone88 Date: Wed, 20 Mar 2024 11:07:33 +0000 Subject: [PATCH 2/6] Add WPush Notification Provider --- src/components/notifications/WPush.vue | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/notifications/WPush.vue b/src/components/notifications/WPush.vue index fa8f3e15..a9f737e5 100644 --- a/src/components/notifications/WPush.vue +++ b/src/components/notifications/WPush.vue @@ -5,16 +5,16 @@
- - -
+ + + https://wpush.cn/ From b933e82e488119975f12a20f68a42f22dd63110d Mon Sep 17 00:00:00 2001 From: Alone88 Date: Thu, 21 Mar 2024 13:22:30 +0800 Subject: [PATCH 3/6] Update WPush Notification Provider Co-authored-by: Frank Elsinga --- server/notification-providers/wpush.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/notification-providers/wpush.js b/server/notification-providers/wpush.js index 9b60365d..21fd37f0 100644 --- a/server/notification-providers/wpush.js +++ b/server/notification-providers/wpush.js @@ -12,14 +12,15 @@ class WPush extends NotificationProvider { const okMsg = "Sent Successfully."; try { - const ret = await axios.post("https://api.wpush.cn/api/v1/send", { + const context = { "title": this.checkStatus(heartbeatJSON, monitorJSON), "content": msg, "apikey": notification.wpushAPIkey, "channel": notification.wpushChannel - }); - if (ret.data.code !== 0) { - return ret.data.message; + }; + const result = await axios.post("https://api.wpush.cn/api/v1/send", context); + if (result.data.code !== 0) { + throw response.data.message; } return okMsg; From 459f80c60cca4804da396225a22434f3883e48ba Mon Sep 17 00:00:00 2001 From: Alone88 Date: Thu, 21 Mar 2024 13:22:49 +0800 Subject: [PATCH 4/6] Update WPush Notification Provider Co-authored-by: Frank Elsinga --- src/components/notifications/WPush.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/WPush.vue b/src/components/notifications/WPush.vue index a9f737e5..136a38fc 100644 --- a/src/components/notifications/WPush.vue +++ b/src/components/notifications/WPush.vue @@ -1,6 +1,6 @@ From 478cd0b8cba037de084aac524981baf2b0a102c3 Mon Sep 17 00:00:00 2001 From: Alone88 Date: Thu, 21 Mar 2024 13:28:04 +0800 Subject: [PATCH 6/6] Fix response not defined for WPush Notification Provider --- server/notification-providers/wpush.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/notification-providers/wpush.js b/server/notification-providers/wpush.js index 21fd37f0..db043f9c 100644 --- a/server/notification-providers/wpush.js +++ b/server/notification-providers/wpush.js @@ -20,7 +20,7 @@ class WPush extends NotificationProvider { }; const result = await axios.post("https://api.wpush.cn/api/v1/send", context); if (result.data.code !== 0) { - throw response.data.message; + throw result.data.message; } return okMsg;