mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-05-20 06:02:33 +02:00
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class SpugPush extends NotificationProvider {
|
|
|
|
name = "SpugPush";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
try {
|
|
let formData = {
|
|
title: "Uptime Kuma Message",
|
|
content: msg
|
|
};
|
|
if (heartbeatJSON) {
|
|
if (heartbeatJSON["status"] === UP) {
|
|
formData.title = `UptimeKuma 「${monitorJSON["name"]}」 is Up`;
|
|
formData.content = `[✅ Up] ${heartbeatJSON["msg"]}`;
|
|
} else if (heartbeatJSON["status"] === DOWN) {
|
|
formData.title = `UptimeKuma 「${monitorJSON["name"]}」 is Down`;
|
|
formData.content = `[🔴 Down] ${heartbeatJSON["msg"]}`;
|
|
}
|
|
}
|
|
const apiUrl = `https://push.spug.cc/send/${notification.templateKey}`;
|
|
await axios.post(apiUrl, formData);
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = SpugPush;
|