mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-04 09:13:21 +00:00
Merge 2.1.X branch to master (#5487)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
class Bale extends NotificationProvider {
|
||||
name = "bale";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
const url = "https://tapi.bale.ai";
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
`${url}/bot${notification.baleBotToken}/sendMessage`,
|
||||
{
|
||||
chat_id: notification.baleChatID,
|
||||
text: msg
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bale;
|
||||
@@ -11,17 +11,23 @@ class DingDing extends NotificationProvider {
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
|
||||
const mentionAll = notification.mentioning === "everyone";
|
||||
const mobileList = notification.mentioning === "specify-mobiles" ? notification.mobileList : [];
|
||||
const userList = notification.mentioning === "specify-users" ? notification.userList : [];
|
||||
const finalList = [ ...mobileList || [], ...userList || [] ];
|
||||
const mentionStr = finalList.length > 0 ? "\n" : "" + finalList.map(item => `@${item}`).join(" ");
|
||||
try {
|
||||
if (heartbeatJSON != null) {
|
||||
let params = {
|
||||
msgtype: "markdown",
|
||||
markdown: {
|
||||
title: `[${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]}`,
|
||||
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||
text: `## [${this.statusToString(heartbeatJSON["status"])}] ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}${mentionStr}`,
|
||||
},
|
||||
"at": {
|
||||
"isAtAll": notification.mentioning === "everyone"
|
||||
at: {
|
||||
isAtAll: mentionAll,
|
||||
atUserIds: userList,
|
||||
atMobiles: mobileList
|
||||
}
|
||||
};
|
||||
if (await this.sendToDingDing(notification, params)) {
|
||||
@@ -31,7 +37,12 @@ class DingDing extends NotificationProvider {
|
||||
let params = {
|
||||
msgtype: "text",
|
||||
text: {
|
||||
content: msg
|
||||
content: `${msg}${mentionStr}`
|
||||
},
|
||||
at: {
|
||||
isAtAll: mentionAll,
|
||||
atUserIds: userList,
|
||||
atMobiles: mobileList
|
||||
}
|
||||
};
|
||||
if (await this.sendToDingDing(notification, params)) {
|
||||
|
||||
+24
-14
@@ -4,6 +4,7 @@ const Alerta = require("./notification-providers/alerta");
|
||||
const AlertNow = require("./notification-providers/alertnow");
|
||||
const AliyunSms = require("./notification-providers/aliyun-sms");
|
||||
const Apprise = require("./notification-providers/apprise");
|
||||
const Bale = require("./notification-providers/bale");
|
||||
const Bark = require("./notification-providers/bark");
|
||||
const Bitrix24 = require("./notification-providers/bitrix24");
|
||||
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
||||
@@ -82,7 +83,6 @@ const SMSPlanet = require("./notification-providers/sms-planet");
|
||||
const SpugPush = require("./notification-providers/spugpush");
|
||||
|
||||
class Notification {
|
||||
|
||||
providerList = {};
|
||||
|
||||
/**
|
||||
@@ -101,6 +101,7 @@ class Notification {
|
||||
new AlertNow(),
|
||||
new AliyunSms(),
|
||||
new Apprise(),
|
||||
new Bale(),
|
||||
new Bark(),
|
||||
new Bitrix24(),
|
||||
new ClickSendSMS(),
|
||||
@@ -179,7 +180,7 @@ class Notification {
|
||||
new Notifery(),
|
||||
];
|
||||
for (let item of list) {
|
||||
if (! item.name) {
|
||||
if (!item.name) {
|
||||
throw new Error("Notification provider without name");
|
||||
}
|
||||
|
||||
@@ -199,9 +200,19 @@ class Notification {
|
||||
* @returns {Promise<string>} Successful msg
|
||||
* @throws Error with fail msg
|
||||
*/
|
||||
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
static async send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON = null,
|
||||
heartbeatJSON = null
|
||||
) {
|
||||
if (this.providerList[notification.type]) {
|
||||
return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
|
||||
return this.providerList[notification.type].send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON,
|
||||
heartbeatJSON
|
||||
);
|
||||
} else {
|
||||
throw new Error("Notification type is not supported");
|
||||
}
|
||||
@@ -223,10 +234,9 @@ class Notification {
|
||||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
} else {
|
||||
bean = R.dispense("notification");
|
||||
}
|
||||
@@ -256,7 +266,7 @@ class Notification {
|
||||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
@@ -272,7 +282,6 @@ class Notification {
|
||||
let exists = commandExistsSync("apprise");
|
||||
return exists;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,16 +292,17 @@ class Notification {
|
||||
*/
|
||||
async function applyNotificationEveryMonitor(notificationID, userID) {
|
||||
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
||||
userID
|
||||
userID,
|
||||
]);
|
||||
|
||||
for (let i = 0; i < monitors.length; i++) {
|
||||
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
|
||||
monitors[i].id,
|
||||
notificationID,
|
||||
]);
|
||||
let checkNotification = await R.findOne(
|
||||
"monitor_notification",
|
||||
" monitor_id = ? AND notification_id = ? ",
|
||||
[ monitors[i].id, notificationID ]
|
||||
);
|
||||
|
||||
if (! checkNotification) {
|
||||
if (!checkNotification) {
|
||||
let relation = R.dispense("monitor_notification");
|
||||
relation.monitor_id = monitors[i].id;
|
||||
relation.notification_id = notificationID;
|
||||
|
||||
Reference in New Issue
Block a user