2021-10-11 05:20:09 -04: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 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-10-11 05:20:09 -04:00
|
|
|
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: {
|
2021-10-11 05:53:13 -04:00
|
|
|
text: msg,
|
2021-10-11 05:20:09 -04:00
|
|
|
},
|
|
|
|
};
|
2021-10-11 05:53:13 -04:00
|
|
|
await axios.post(feishuWebHookUrl, testdata);
|
2021-10-11 05:20:09 -04:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 03:43:03 -04:00
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
2021-10-11 05:20:09 -04:00
|
|
|
let downdata = {
|
|
|
|
msg_type: "post",
|
|
|
|
content: {
|
|
|
|
post: {
|
|
|
|
zh_cn: {
|
2021-11-01 01:31:31 -04:00
|
|
|
title: "UptimeKuma Alert: [Down] " + monitorJSON["name"],
|
2021-10-11 05:20:09 -04:00
|
|
|
content: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
tag: "text",
|
|
|
|
text:
|
|
|
|
"[Down] " +
|
|
|
|
heartbeatJSON["msg"] +
|
2023-05-29 13:24:40 -04:00
|
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
2021-10-11 05:20:09 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
await axios.post(feishuWebHookUrl, downdata);
|
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
2022-04-17 03:43:03 -04:00
|
|
|
if (heartbeatJSON["status"] === UP) {
|
2021-10-11 05:20:09 -04:00
|
|
|
let updata = {
|
|
|
|
msg_type: "post",
|
|
|
|
content: {
|
|
|
|
post: {
|
|
|
|
zh_cn: {
|
2021-11-01 01:31:31 -04:00
|
|
|
title: "UptimeKuma Alert: [Up] " + monitorJSON["name"],
|
2021-10-11 05:20:09 -04:00
|
|
|
content: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
tag: "text",
|
|
|
|
text:
|
|
|
|
"[Up] " +
|
|
|
|
heartbeatJSON["msg"] +
|
2023-05-29 13:24:40 -04:00
|
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
2021-10-11 05:20:09 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
await axios.post(feishuWebHookUrl, updata);
|
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Feishu;
|