mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-24 21:24:28 -08:00
Add support for Pushdeer notifications
This commit is contained in:
parent
2e3414135f
commit
fb059f5e91
52
server/notification-providers/pushdeer.js
Normal file
52
server/notification-providers/pushdeer.js
Normal 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;
|
|
@ -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) {
|
||||||
|
|
19
src/components/notifications/Pushdeer.vue
Normal file
19
src/components/notifications/Pushdeer.vue
Normal 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>
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue