mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-22 14:05:18 -05:00
2ce5c28ed4
# Conflicts: # src/languages/en.js
67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const Slack = require("./slack");
|
|
const { setting } = require("../util-server");
|
|
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
|
|
|
class RocketChat extends NotificationProvider {
|
|
|
|
name = "rocket.chat";
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
try {
|
|
if (heartbeatJSON == null) {
|
|
let data = {
|
|
"text": msg,
|
|
"channel": notification.rocketchannel,
|
|
"username": notification.rocketusername,
|
|
"icon_emoji": notification.rocketiconemo,
|
|
};
|
|
await axios.post(notification.rocketwebhookURL, data);
|
|
return okMsg;
|
|
}
|
|
|
|
const time = heartbeatJSON["time"];
|
|
|
|
let data = {
|
|
"text": "Uptime Kuma Alert",
|
|
"channel": notification.rocketchannel,
|
|
"username": notification.rocketusername,
|
|
"icon_emoji": notification.rocketiconemo,
|
|
"attachments": [
|
|
{
|
|
"title": "Uptime Kuma Alert *Time (UTC)*\n" + time,
|
|
"text": "*Message*\n" + msg,
|
|
}
|
|
]
|
|
};
|
|
|
|
// Color
|
|
if (heartbeatJSON.status === DOWN) {
|
|
data.attachments[0].color = "#ff0000";
|
|
} else {
|
|
data.attachments[0].color = "#32cd32";
|
|
}
|
|
|
|
if (notification.rocketbutton) {
|
|
await Slack.deprecateURL(notification.rocketbutton);
|
|
}
|
|
|
|
const baseURL = await setting("primaryBaseURL");
|
|
|
|
if (baseURL) {
|
|
data.attachments[0].title_link = baseURL + getMonitorRelativeURL(monitorJSON.id);
|
|
}
|
|
|
|
await axios.post(notification.rocketwebhookURL, data);
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = RocketChat;
|