summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/pushdeer.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/notification-providers/pushdeer.js')
-rw-r--r--server/notification-providers/pushdeer.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/server/notification-providers/pushdeer.js b/server/notification-providers/pushdeer.js
new file mode 100644
index 0000000..276c2f4
--- /dev/null
+++ b/server/notification-providers/pushdeer.js
@@ -0,0 +1,55 @@
+const NotificationProvider = require("./notification-provider");
+const axios = require("axios");
+const { DOWN, UP } = require("../../src/util");
+
+class PushDeer extends NotificationProvider {
+ name = "PushDeer";
+
+ /**
+ * @inheritdoc
+ */
+ async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
+ const okMsg = "Sent Successfully.";
+ const serverUrl = notification.pushdeerServer || "https://api2.pushdeer.com";
+ const url = `${serverUrl.trim().replace(/\/*$/, "")}/message/push`;
+
+ let valid = msg != null && monitorJSON != null && heartbeatJSON != null;
+
+ let title;
+ if (valid && heartbeatJSON.status === UP) {
+ title = "## Uptime Kuma: " + monitorJSON.name + " up";
+ } else if (valid && heartbeatJSON.status === DOWN) {
+ title = "## Uptime Kuma: " + monitorJSON.name + " down";
+ } else {
+ title = "## Uptime Kuma Message";
+ }
+
+ let data = {
+ "pushkey": notification.pushdeerKey,
+ "text": title,
+ "desp": msg.replace(/\n/g, "\n\n"),
+ "type": "markdown",
+ };
+
+ try {
+ let res = await axios.post(url, data);
+
+ if ("error" in res.data) {
+ let error = res.data.error;
+ this.throwGeneralAxiosError(error);
+ }
+ if (res.data.content.result.length === 0) {
+ let error = "Invalid PushDeer key";
+ this.throwGeneralAxiosError(error);
+ } else if (JSON.parse(res.data.content.result[0]).success !== "ok") {
+ let error = "Unknown error";
+ this.throwGeneralAxiosError(error);
+ }
+ return okMsg;
+ } catch (error) {
+ this.throwGeneralAxiosError(error);
+ }
+ }
+}
+
+module.exports = PushDeer;