Add support for Pushdeer notifications

This commit is contained in:
ngc7331 2022-04-02 14:40:33 +08:00 committed by Louis Lam
parent 2e3414135f
commit fb059f5e91
4 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,52 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class Pushdeer extends NotificationProvider {
name = "Pushdeer";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
let pushdeerlink = "https://api2.pushdeer.com/message/push";
let valid = msg != null && monitorJSON != null && heartbeatJSON != null;
let title;
if (valid && heartbeatJSON.status == UP) {
title = "## UptimeKuma: " + monitorJSON.name + " up";
} else if (valid && heartbeatJSON.status == DOWN) {
title = "## UptimeKuma: " + monitorJSON.name + " down";
} else {
title = "## UptimeKuma Message";
}
let data = {
"pushkey": notification.pushdeerKey,
"text": title,
"desp": msg.replace(/\n/g, "\n\n"),
"type": "markdown",
};
try {
let res = await axios.post(pushdeerlink, 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;

View File

@ -32,6 +32,7 @@ const GoogleChat = require("./notification-providers/google-chat");
const Gorush = require("./notification-providers/gorush"); const Gorush = require("./notification-providers/gorush");
const Alerta = require("./notification-providers/alerta"); const Alerta = require("./notification-providers/alerta");
const OneBot = require("./notification-providers/onebot"); const OneBot = require("./notification-providers/onebot");
const Pushdeer = require("./notification-providers/pushdeer");
class Notification { class Notification {
@ -75,6 +76,7 @@ class Notification {
new Gorush(), new Gorush(),
new Alerta(), new Alerta(),
new OneBot(), new OneBot(),
new Pushdeer(),
]; ];
for (let item of list) { for (let item of list) {

View File

@ -0,0 +1,19 @@
<template>
<div class="mb-3">
<label for="pushdeer-key" class="form-label">Pushdeer Key</label>
<HiddenInput id="pushdeer-key" v-model="$parent.notification.pushdeerKey" :required="true" autocomplete="one-time-code" placeholder="PDUxxxx"></HiddenInput>
</div>
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
<a href="http://www.pushdeer.com/" target="_blank">http://www.pushdeer.com/</a>
</i18n-t>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
};
</script>

View File

@ -30,6 +30,7 @@ import GoogleChat from "./GoogleChat.vue";
import Gorush from "./Gorush.vue"; import Gorush from "./Gorush.vue";
import Alerta from "./Alerta.vue"; import Alerta from "./Alerta.vue";
import OneBot from "./OneBot.vue"; import OneBot from "./OneBot.vue";
import Pushdeer from "./Pushdeer.vue";
/** /**
* Manage all notification form. * Manage all notification form.
@ -69,6 +70,7 @@ const NotificationFormList = {
"gorush": Gorush, "gorush": Gorush,
"alerta": Alerta, "alerta": Alerta,
"OneBot": OneBot, "OneBot": OneBot,
"Pushdeer": Pushdeer,
}; };
export default NotificationFormList; export default NotificationFormList;