2021-10-11 02:20:09 -07:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
|
|
|
|
class Feishu extends NotificationProvider {
|
|
|
|
name = "Feishu";
|
|
|
|
|
2023-08-11 00:46:41 -07:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-10-11 02:20:09 -07:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 06:21:15 -07:00
|
|
|
const okMsg = "Sent Successfully.";
|
2021-10-11 02:20:09 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
|
|
|
let testdata = {
|
|
|
|
msg_type: "text",
|
|
|
|
content: {
|
2021-10-11 02:53:13 -07:00
|
|
|
text: msg,
|
2021-10-11 02:20:09 -07:00
|
|
|
},
|
|
|
|
};
|
2024-03-14 06:21:15 -07:00
|
|
|
await axios.post(notification.feishuWebHookUrl, testdata);
|
2021-10-11 02:20:09 -07:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 00:43:03 -07:00
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
2021-10-11 02:20:09 -07:00
|
|
|
let downdata = {
|
|
|
|
msg_type: "post",
|
|
|
|
content: {
|
|
|
|
post: {
|
|
|
|
zh_cn: {
|
2021-10-31 22:31:31 -07:00
|
|
|
title: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
|
2021-10-11 02:20:09 -07:00
|
|
|
content: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
tag: "text",
|
|
|
|
text:
|
|
|
|
"[Down] " +
|
|
|
|
heartbeatJSON["msg"] +
|
2023-05-29 10:24:40 -07:00
|
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
2021-10-11 02:20:09 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2024-03-14 06:21:15 -07:00
|
|
|
await axios.post(notification.feishuWebHookUrl, downdata);
|
2021-10-11 02:20:09 -07:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 00:43:03 -07:00
|
|
|
if (heartbeatJSON["status"] === UP) {
|
2021-10-11 02:20:09 -07:00
|
|
|
let updata = {
|
|
|
|
msg_type: "post",
|
|
|
|
content: {
|
|
|
|
post: {
|
|
|
|
zh_cn: {
|
2021-10-31 22:31:31 -07:00
|
|
|
title: "UptimeKuma Alert: [Up] " + monitorJSON["name"],
|
2021-10-11 02:20:09 -07:00
|
|
|
content: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
tag: "text",
|
|
|
|
text:
|
|
|
|
"[Up] " +
|
|
|
|
heartbeatJSON["msg"] +
|
2023-05-29 10:24:40 -07:00
|
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
2021-10-11 02:20:09 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2024-03-14 06:21:15 -07:00
|
|
|
await axios.post(notification.feishuWebHookUrl, updata);
|
2021-10-11 02:20:09 -07:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Feishu;
|