Merge branch 'master' into feature/umami-analytics-status-page

This commit is contained in:
Frank Elsinga
2025-10-27 22:29:44 +01:00
committed by GitHub
18 changed files with 127 additions and 65 deletions
+2 -1
View File
@@ -578,7 +578,8 @@ class Monitor extends BeanModel {
}
}
if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID === this.id) {
// eslint-disable-next-line eqeqeq
if (process.env.UPTIME_KUMA_LOG_RESPONSE_BODY_MONITOR_ID == this.id) {
log.info("monitor", res.data);
}
@@ -2,13 +2,13 @@ const { MonitorType } = require("./monitor-type");
const { chromium } = require("playwright-core");
const { UP, log } = require("../../src/util");
const { Settings } = require("../settings");
const commandExistsSync = require("command-exists").sync;
const childProcess = require("child_process");
const path = require("path");
const Database = require("../database");
const jwt = require("jsonwebtoken");
const config = require("../config");
const { RemoteBrowser } = require("../remote-browser");
const { commandExists } = require("../util-server");
/**
* Cached instance of a browser
@@ -122,7 +122,7 @@ async function prepareChromeExecutable(executablePath) {
executablePath = "/usr/bin/chromium";
// Install chromium in container via apt install
if ( !commandExistsSync(executablePath)) {
if (! await commandExists(executablePath)) {
await new Promise((resolve, reject) => {
log.info("Chromium", "Installing Chromium...");
let child = childProcess.exec("apt update && apt --yes --no-install-recommends install chromium fonts-indic fonts-noto fonts-noto-cjk");
@@ -146,7 +146,7 @@ async function prepareChromeExecutable(executablePath) {
}
} else {
executablePath = findChrome(allowedList);
executablePath = await findChrome(allowedList);
}
} else {
// User specified a path
@@ -160,20 +160,20 @@ async function prepareChromeExecutable(executablePath) {
/**
* Find the chrome executable
* @param {any[]} executables Executables to search through
* @returns {any} Executable
* @throws Could not find executable
* @param {string[]} executables Executables to search through
* @returns {Promise<string>} Executable
* @throws {Error} Could not find executable
*/
function findChrome(executables) {
async function findChrome(executables) {
// Use the last working executable, so we don't have to search for it again
if (lastAutoDetectChromeExecutable) {
if (commandExistsSync(lastAutoDetectChromeExecutable)) {
if (await commandExists(lastAutoDetectChromeExecutable)) {
return lastAutoDetectChromeExecutable;
}
}
for (let executable of executables) {
if (commandExistsSync(executable)) {
if (await commandExists(executable)) {
lastAutoDetectChromeExecutable = executable;
return executable;
}
+8 -7
View File
@@ -23,9 +23,7 @@ class PagerDuty extends NotificationProvider {
if (heartbeatJSON.status === UP) {
const title = "Uptime Kuma Monitor ✅ Up";
const eventAction = notification.pagerdutyAutoResolve || null;
return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, eventAction);
return this.postNotification(notification, title, heartbeatJSON.msg, monitorJSON, "resolve");
}
if (heartbeatJSON.status === DOWN) {
@@ -63,10 +61,6 @@ class PagerDuty extends NotificationProvider {
*/
async postNotification(notification, title, body, monitorInfo, eventAction = "trigger") {
if (eventAction == null) {
return "No action required";
}
let monitorUrl;
if (monitorInfo.type === "port") {
monitorUrl = monitorInfo.hostname;
@@ -79,6 +73,13 @@ class PagerDuty extends NotificationProvider {
monitorUrl = monitorInfo.url;
}
if (eventAction === "resolve") {
if (notification.pagerdutyAutoResolve === "0") {
return "no action required";
}
eventAction = notification.pagerdutyAutoResolve;
}
const options = {
method: "POST",
url: notification.pagerdutyIntegrationUrl,
+22 -2
View File
@@ -12,6 +12,8 @@ class Webhook extends NotificationProvider {
const okMsg = "Sent Successfully.";
try {
const httpMethod = notification.httpMethod.toLowerCase() || "post";
let data = {
heartbeat: heartbeatJSON,
monitor: monitorJSON,
@@ -21,7 +23,19 @@ class Webhook extends NotificationProvider {
headers: {}
};
if (notification.webhookContentType === "form-data") {
if (httpMethod === "get") {
config.params = {
msg: msg
};
if (heartbeatJSON) {
config.params.heartbeat = JSON.stringify(heartbeatJSON);
}
if (monitorJSON) {
config.params.monitor = JSON.stringify(monitorJSON);
}
} else if (notification.webhookContentType === "form-data") {
const formData = new FormData();
formData.append("data", JSON.stringify(data));
config.headers = formData.getHeaders();
@@ -42,7 +56,13 @@ class Webhook extends NotificationProvider {
}
config = this.getAxiosConfigWithProxy(config);
await axios.post(notification.webhookURL, data, config);
if (httpMethod === "get") {
await axios.get(notification.webhookURL, config);
} else {
await axios.post(notification.webhookURL, data, config);
}
return okMsg;
} catch (error) {
+4 -5
View File
@@ -81,6 +81,7 @@ const Brevo = require("./notification-providers/brevo");
const YZJ = require("./notification-providers/yzj");
const SMSPlanet = require("./notification-providers/sms-planet");
const SpugPush = require("./notification-providers/spugpush");
const { commandExists } = require("./util-server");
class Notification {
providerList = {};
@@ -275,12 +276,10 @@ class Notification {
/**
* Check if apprise exists
* @returns {boolean} Does the command apprise exist?
* @returns {Promise<boolean>} Does the command apprise exist?
*/
static checkApprise() {
let commandExistsSync = require("command-exists").sync;
let exists = commandExistsSync("apprise");
return exists;
static async checkApprise() {
return await commandExists("apprise");
}
}
+1 -1
View File
@@ -1503,7 +1503,7 @@ let needSetup = false;
socket.on("checkApprise", async (callback) => {
try {
checkLogin(socket);
callback(Notification.checkApprise());
callback(await Notification.checkApprise());
} catch (e) {
callback(false);
}
+16
View File
@@ -1116,3 +1116,19 @@ function fsExists(path) {
});
}
module.exports.fsExists = fsExists;
/**
* By default, command-exists will throw a null error if the command does not exist, which is ugly. The function makes it better.
* Read more: https://github.com/mathisonian/command-exists/issues/22
* @param {string} command Command to check
* @returns {Promise<boolean>} True if command exists, false otherwise
*/
async function commandExists(command) {
try {
await require("command-exists")(command);
return true;
} catch (e) {
return false;
}
}
module.exports.commandExists = commandExists;