diff --git a/server/notification-providers/serverchan.js b/server/notification-providers/serverchan.js new file mode 100644 index 00000000..fbf99f80 --- /dev/null +++ b/server/notification-providers/serverchan.js @@ -0,0 +1,36 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class ServerChan extends NotificationProvider { + + name = "ServerChan"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + await axios.post(`https://sctapi.ftqq.com/${notification.serverChanSendKey}.send`, { + "title": this.checkStatus(heartbeatJSON, monitorJSON), + "desp": msg, + }); + + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + + 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 = ServerChan; diff --git a/server/notification.js b/server/notification.js index 6f71783b..3bf51243 100644 --- a/server/notification.js +++ b/server/notification.js @@ -40,6 +40,7 @@ const Webhook = require("./notification-providers/webhook"); const WeCom = require("./notification-providers/wecom"); const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); +const ServerChan = require("./notification-providers/serverchan"); class Notification { @@ -80,6 +81,7 @@ class Notification { new Pushover(), new Pushy(), new RocketChat(), + new ServerChan(), new SerwerSMS(), new Signal(), new SMSManager(), diff --git a/src/components/notifications/ServerChan.vue b/src/components/notifications/ServerChan.vue new file mode 100644 index 00000000..cec75675 --- /dev/null +++ b/src/components/notifications/ServerChan.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 07ed2cd1..6add06ea 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -26,6 +26,7 @@ import PushDeer from "./PushDeer.vue"; import Pushover from "./Pushover.vue"; import Pushy from "./Pushy.vue"; import RocketChat from "./RocketChat.vue"; +import ServerChan from "./ServerChan.vue"; import SerwerSMS from "./SerwerSMS.vue"; import Signal from "./Signal.vue"; import SMSManager from "./SMSManager.vue"; @@ -85,6 +86,7 @@ const NotificationFormList = { "webhook": Webhook, "WeCom": WeCom, "GoAlert": GoAlert, + "ServerChan": ServerChan, }; export default NotificationFormList;