mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-04 23:11:24 +03:00
8a92054c2b
* Added JSDoc to eslint rules Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Fixed JSDoc eslint errors Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Update the check-linters workflow to Node.js 20 --------- Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
84 lines
3 KiB
JavaScript
84 lines
3 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class Feishu extends NotificationProvider {
|
|
name = "Feishu";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
let feishuWebHookUrl = notification.feishuWebHookUrl;
|
|
|
|
try {
|
|
if (heartbeatJSON == null) {
|
|
let testdata = {
|
|
msg_type: "text",
|
|
content: {
|
|
text: msg,
|
|
},
|
|
};
|
|
await axios.post(feishuWebHookUrl, testdata);
|
|
return okMsg;
|
|
}
|
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
|
let downdata = {
|
|
msg_type: "post",
|
|
content: {
|
|
post: {
|
|
zh_cn: {
|
|
title: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
|
|
content: [
|
|
[
|
|
{
|
|
tag: "text",
|
|
text:
|
|
"[Down] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
|
},
|
|
],
|
|
],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
await axios.post(feishuWebHookUrl, downdata);
|
|
return okMsg;
|
|
}
|
|
|
|
if (heartbeatJSON["status"] === UP) {
|
|
let updata = {
|
|
msg_type: "post",
|
|
content: {
|
|
post: {
|
|
zh_cn: {
|
|
title: "UptimeKuma Alert: [Up] " + monitorJSON["name"],
|
|
content: [
|
|
[
|
|
{
|
|
tag: "text",
|
|
text:
|
|
"[Up] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
|
},
|
|
],
|
|
],
|
|
},
|
|
},
|
|
},
|
|
};
|
|
await axios.post(feishuWebHookUrl, updata);
|
|
return okMsg;
|
|
}
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Feishu;
|