2021-09-07 10:42:46 -04:00
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
2021-10-07 05:39:58 -04:00
|
|
|
const Slack = require("./slack");
|
2022-04-13 12:30:32 -04:00
|
|
|
const { getMonitorRelativeURL, DOWN } = require("../../src/util");
|
2024-09-24 05:51:21 -04:00
|
|
|
const { Settings } = require("../settings");
|
2021-09-07 10:42:46 -04:00
|
|
|
|
|
|
|
class RocketChat extends NotificationProvider {
|
|
|
|
name = "rocket.chat";
|
|
|
|
|
2023-08-11 03:46:41 -04:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2021-09-07 10:42:46 -04:00
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
2024-03-14 09:21:15 -04:00
|
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
|
2021-09-07 10:42:46 -04:00
|
|
|
try {
|
|
|
|
if (heartbeatJSON == null) {
|
|
|
|
let data = {
|
2021-10-07 05:39:58 -04:00
|
|
|
"text": msg,
|
2021-09-07 10:42:46 -04:00
|
|
|
"channel": notification.rocketchannel,
|
|
|
|
"username": notification.rocketusername,
|
|
|
|
"icon_emoji": notification.rocketiconemo,
|
2021-10-07 05:39:58 -04:00
|
|
|
};
|
|
|
|
await axios.post(notification.rocketwebhookURL, data);
|
2021-09-07 10:42:46 -04:00
|
|
|
return okMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
"text": "Uptime Kuma Alert",
|
|
|
|
"channel": notification.rocketchannel,
|
|
|
|
"username": notification.rocketusername,
|
|
|
|
"icon_emoji": notification.rocketiconemo,
|
|
|
|
"attachments": [
|
|
|
|
{
|
2023-05-29 13:24:40 -04:00
|
|
|
"title": `Uptime Kuma Alert *Time (${heartbeatJSON["timezone"]})*\n${heartbeatJSON["localDateTime"]}`,
|
2021-09-07 10:42:46 -04:00
|
|
|
"text": "*Message*\n" + msg,
|
|
|
|
}
|
|
|
|
]
|
2021-10-07 05:39:58 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Color
|
|
|
|
if (heartbeatJSON.status === DOWN) {
|
|
|
|
data.attachments[0].color = "#ff0000";
|
|
|
|
} else {
|
|
|
|
data.attachments[0].color = "#32cd32";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notification.rocketbutton) {
|
|
|
|
await Slack.deprecateURL(notification.rocketbutton);
|
2021-09-07 10:42:46 -04:00
|
|
|
}
|
2021-10-07 05:39:58 -04:00
|
|
|
|
2024-09-24 05:51:21 -04:00
|
|
|
const baseURL = await Settings.get("primaryBaseURL");
|
2021-10-07 05:39:58 -04:00
|
|
|
|
|
|
|
if (baseURL) {
|
|
|
|
data.attachments[0].title_link = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
await axios.post(notification.rocketwebhookURL, data);
|
2021-09-07 10:42:46 -04:00
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
2021-10-07 05:39:58 -04:00
|
|
|
this.throwGeneralAxiosError(error);
|
2021-09-07 10:42:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RocketChat;
|