mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-19 12:01:06 +08:00
feat: Support YZJ notification provider (#5686)
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
57
server/notification-providers/yzj.js
Normal file
57
server/notification-providers/yzj.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
const { default: axios } = require("axios");
|
||||
|
||||
class YZJ extends NotificationProvider {
|
||||
name = "YZJ";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
let okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
if (heartbeatJSON !== null) {
|
||||
msg = `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
||||
}
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
const params = {
|
||||
content: msg
|
||||
};
|
||||
// yzjtype=0 => general robot
|
||||
const url = `${notification.yzjWebHookUrl}?yzjtype=0&yzjtoken=${notification.yzjToken}`;
|
||||
|
||||
const result = await axios.post(url, params, config);
|
||||
if (!result.data?.success) {
|
||||
throw new Error(result.data?.errmsg ?? "yzj's server did not respond with the expected result");
|
||||
}
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert status constant to string
|
||||
* @param {string} status The status constant
|
||||
* @returns {string} status
|
||||
*/
|
||||
statusToString(status) {
|
||||
switch (status) {
|
||||
case DOWN:
|
||||
return "❌";
|
||||
case UP:
|
||||
return "✅";
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = YZJ;
|
@@ -69,6 +69,7 @@ const Cellsynt = require("./notification-providers/cellsynt");
|
||||
const Onesender = require("./notification-providers/onesender");
|
||||
const Wpush = require("./notification-providers/wpush");
|
||||
const SendGrid = require("./notification-providers/send-grid");
|
||||
const YZJ = require("./notification-providers/yzj");
|
||||
|
||||
class Notification {
|
||||
|
||||
@@ -154,7 +155,8 @@ class Notification {
|
||||
new GtxMessaging(),
|
||||
new Cellsynt(),
|
||||
new Wpush(),
|
||||
new SendGrid()
|
||||
new SendGrid(),
|
||||
new YZJ()
|
||||
];
|
||||
for (let item of list) {
|
||||
if (! item.name) {
|
||||
|
Reference in New Issue
Block a user