mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-21 12:11:21 +08:00
Merge branch 'master' into hide-uptime-percentage
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
const { setting } = require("../util-server");
|
||||
const { getMonitorRelativeURL } = require("../../src/util");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
const { getMonitorRelativeURL, UP } = require("../../src/util");
|
||||
|
||||
class GoogleChat extends NotificationProvider {
|
||||
name = "GoogleChat";
|
||||
@@ -16,26 +15,71 @@ class GoogleChat extends NotificationProvider {
|
||||
try {
|
||||
// Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic
|
||||
|
||||
let textMsg = "";
|
||||
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
||||
textMsg = "✅ Application is back online\n";
|
||||
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
||||
textMsg = "🔴 Application went down\n";
|
||||
let chatHeader = {
|
||||
title: "Uptime Kuma Alert",
|
||||
};
|
||||
|
||||
if (monitorJSON && heartbeatJSON) {
|
||||
chatHeader["title"] =
|
||||
heartbeatJSON["status"] === UP
|
||||
? `✅ ${monitorJSON["name"]} is back online`
|
||||
: `🔴 ${monitorJSON["name"]} went down`;
|
||||
}
|
||||
|
||||
if (monitorJSON && monitorJSON.name) {
|
||||
textMsg += `*${monitorJSON.name}*\n`;
|
||||
// always show msg
|
||||
let sectionWidgets = [
|
||||
{
|
||||
textParagraph: {
|
||||
text: `<b>Message:</b>\n${msg}`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// add time if available
|
||||
if (heartbeatJSON) {
|
||||
sectionWidgets.push({
|
||||
textParagraph: {
|
||||
text: `<b>Time (${heartbeatJSON["timezone"]}):</b>\n${heartbeatJSON["localDateTime"]}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
textMsg += `${msg}`;
|
||||
|
||||
// add button for monitor link if available
|
||||
const baseURL = await setting("primaryBaseURL");
|
||||
if (baseURL && monitorJSON) {
|
||||
textMsg += `\n${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
|
||||
if (baseURL) {
|
||||
const urlPath = monitorJSON ? getMonitorRelativeURL(monitorJSON.id) : "/";
|
||||
sectionWidgets.push({
|
||||
buttonList: {
|
||||
buttons: [
|
||||
{
|
||||
text: "Visit Uptime Kuma",
|
||||
onClick: {
|
||||
openLink: {
|
||||
url: baseURL + urlPath,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const data = {
|
||||
"text": textMsg,
|
||||
let chatSections = [
|
||||
{
|
||||
widgets: sectionWidgets,
|
||||
},
|
||||
];
|
||||
|
||||
// construct json data
|
||||
let data = {
|
||||
cardsV2: [
|
||||
{
|
||||
card: {
|
||||
header: chatHeader,
|
||||
sections: chatSections,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
await axios.post(notification.googleChatWebhookURL, data);
|
||||
|
@@ -23,6 +23,8 @@ class HomeAssistant extends NotificationProvider {
|
||||
...(notificationService !== "persistent_notification" && { data: {
|
||||
name: monitorJSON?.name,
|
||||
status: heartbeatJSON?.status,
|
||||
channel: "Uptime Kuma",
|
||||
icon_url: "https://github.com/louislam/uptime-kuma/blob/master/public/icon.png?raw=true",
|
||||
} }),
|
||||
},
|
||||
{
|
||||
|
@@ -1619,15 +1619,15 @@ async function afterLogin(socket, user) {
|
||||
socket.join(user.id);
|
||||
|
||||
let monitorList = await server.sendMonitorList(socket);
|
||||
await sendInfo(socket);
|
||||
await server.sendMaintenanceList(socket);
|
||||
await sendNotificationList(socket);
|
||||
await sendProxyList(socket);
|
||||
await sendDockerHostList(socket);
|
||||
await sendAPIKeyList(socket);
|
||||
await sendRemoteBrowserList(socket);
|
||||
|
||||
await sleep(500);
|
||||
await Promise.allSettled([
|
||||
sendInfo(socket),
|
||||
server.sendMaintenanceList(socket),
|
||||
sendNotificationList(socket),
|
||||
sendProxyList(socket),
|
||||
sendDockerHostList(socket),
|
||||
sendAPIKeyList(socket),
|
||||
sendRemoteBrowserList(socket),
|
||||
]);
|
||||
|
||||
await StatusPage.sendStatusPageList(io, socket);
|
||||
|
||||
|
Reference in New Issue
Block a user