From 71f031c14e90ad09e4d04b0283ee86ae1a813be1 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Mon, 23 May 2022 10:32:36 +0200 Subject: [PATCH] add ntfy support ref https://github.com/louislam/uptime-kuma/issues/1622 --- server/notification-providers/ntfy.js | 29 +++++++++++++++++++++++ server/notification.js | 2 ++ src/components/notifications/Ntfy.vue | 34 +++++++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 server/notification-providers/ntfy.js create mode 100644 src/components/notifications/Ntfy.vue diff --git a/server/notification-providers/ntfy.js b/server/notification-providers/ntfy.js new file mode 100644 index 000000000..8a0ef6250 --- /dev/null +++ b/server/notification-providers/ntfy.js @@ -0,0 +1,29 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Ntfy extends NotificationProvider { + + name = "ntfy"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + if (notification.ntfyserverurl && notification.ntfyserverurl.endsWith("/")) { + notification.ntfyserverurl = notification.ntfyserverurl.slice(0, -1); + } + await axios.post(`${notification.ntfyserverurl}`, { + "topic": notification.ntfytopic, + "message": msg, + "priority": notification.ntfyPriority || 4, + "title": "Uptime-Kuma", + }) + + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Ntfy; diff --git a/server/notification.js b/server/notification.js index 269e94440..b272972fe 100644 --- a/server/notification.js +++ b/server/notification.js @@ -2,6 +2,7 @@ const { R } = require("redbean-node"); const Apprise = require("./notification-providers/apprise"); const Discord = require("./notification-providers/discord"); const Gotify = require("./notification-providers/gotify"); +const Ntfy = require("./notification-providers/ntfy"); const Line = require("./notification-providers/line"); const LunaSea = require("./notification-providers/lunasea"); const Mattermost = require("./notification-providers/mattermost"); @@ -51,6 +52,7 @@ class Notification { new Discord(), new Teams(), new Gotify(), + new Ntfy(), new Line(), new LunaSea(), new Feishu(), diff --git a/src/components/notifications/Ntfy.vue b/src/components/notifications/Ntfy.vue new file mode 100644 index 000000000..39a649709 --- /dev/null +++ b/src/components/notifications/Ntfy.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 496d35fa0..c6fe944ca 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -4,6 +4,7 @@ import Discord from "./Discord.vue"; import Webhook from "./Webhook.vue"; import Signal from "./Signal.vue"; import Gotify from "./Gotify.vue"; +import Ntfy from "./Ntfy.vue"; import Slack from "./Slack.vue"; import RocketChat from "./RocketChat.vue"; import Teams from "./Teams.vue"; @@ -45,6 +46,7 @@ const NotificationFormList = { "teams": Teams, "signal": Signal, "gotify": Gotify, + "ntfy": Ntfy, "slack": Slack, "rocket.chat": RocketChat, "pushover": Pushover,