chore: make the monitors consistently log using this.name where appropriate (#6651)

This commit is contained in:
Frank Elsinga 2026-01-08 22:38:10 +01:00 committed by GitHub
parent 267c1402df
commit 5accda390e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 46 additions and 34 deletions

View File

@ -144,7 +144,7 @@ class MqttMonitorType extends MonitorType {
}
const timeoutID = setTimeout(() => {
log.debug("mqtt", "MQTT timeout triggered");
log.debug(this.name, "MQTT timeout triggered");
client.end();
reject(new Error("Timeout, Message not received"));
}, interval * 1000 * 0.8);
@ -159,7 +159,7 @@ class MqttMonitorType extends MonitorType {
}
}
log.debug("mqtt", `MQTT connecting to ${mqttUrl}`);
log.debug(this.name, `MQTT connecting to ${mqttUrl}`);
let client = mqtt.connect(mqttUrl, {
username,
@ -168,11 +168,11 @@ class MqttMonitorType extends MonitorType {
});
client.on("connect", () => {
log.debug("mqtt", "MQTT connected");
log.debug(this.name, "MQTT connected");
try {
client.subscribe(topic, () => {
log.debug("mqtt", "MQTT subscribed to topic");
log.debug(this.name, "MQTT subscribed to topic");
});
} catch (e) {
client.end();

View File

@ -49,7 +49,7 @@ class PostgresMonitorType extends MonitorType {
const client = new Client(config);
client.on("error", (error) => {
log.debug("postgres", "Error caught in the error event handler.");
log.debug(this.name, "Error caught in the error event handler.");
reject(error);
});

View File

@ -63,7 +63,6 @@ if (process.platform === "win32") {
* @returns {Promise<boolean>} The executable is allowed?
*/
async function isAllowedChromeExecutable(executablePath) {
console.log(config.args);
if (config.args["allow-all-chrome-exec"] || process.env.UPTIME_KUMA_ALLOW_ALL_CHROME_EXEC === "1") {
return true;
}
@ -102,7 +101,7 @@ async function getBrowser() {
*/
async function getRemoteBrowser(remoteBrowserID, userId) {
let remoteBrowser = await RemoteBrowser.get(remoteBrowserID, userId);
log.debug("MONITOR", `Using remote browser: ${remoteBrowser.name} (${remoteBrowser.id})`);
log.debug("chromium", `Using remote browser: ${remoteBrowser.name} (${remoteBrowser.id})`);
browser = await chromium.connect(remoteBrowser.url);
return browser;
}
@ -120,31 +119,7 @@ async function prepareChromeExecutable(executablePath) {
} else if (!executablePath) {
if (process.env.UPTIME_KUMA_IS_CONTAINER) {
executablePath = "/usr/bin/chromium";
// Install chromium in container via apt install
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");
// On exit
child.on("exit", (code) => {
log.info("Chromium", "apt install chromium exited with code " + code);
if (code === 0) {
log.info("Chromium", "Installed Chromium");
let version = childProcess.execSync(executablePath + " --version").toString("utf8");
log.info("Chromium", "Chromium version: " + version);
resolve();
} else if (code === 100) {
reject(new Error("Installing Chromium, please wait..."));
} else {
reject(new Error("apt install chromium failed with code " + code));
}
});
});
}
await installChromiumViaApt(executablePath);
} else {
executablePath = await findChrome(allowedList);
}
@ -158,6 +133,43 @@ async function prepareChromeExecutable(executablePath) {
return executablePath;
}
/**
* Installs Chromium and required font packages via APT if the Chromium executable
* is not already available.
* @async
* @param {string} executablePath - Path to the Chromium executable used to check
* whether Chromium is available and to query its version after installation.
* @returns {Promise<void>} Resolves when Chromium is successfully installed or
* when no installation is required.
* @throws {Error} If the APT installation fails or exits with an unexpected
* exit code.
*/
async function installChromiumViaApt(executablePath) {
if (await commandExists(executablePath)) {
return
}
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");
// On exit
child.on("exit", (code) => {
log.info("chromium", "apt install chromium exited with code " + code);
if (code === 0) {
log.info("chromium", "Installed Chromium");
let version = childProcess.execSync(executablePath + " --version").toString("utf8");
log.info("chromium", "Chromium version: " + version);
resolve();
} else if (code === 100) {
reject(new Error("Installing Chromium, please wait..."));
} else {
reject(new Error("apt install chromium failed with code " + code));
}
});
});
}
/**
* Find the chrome executable
* @param {string[]} executables Executables to search through
@ -201,7 +213,7 @@ async function testChrome(executablePath) {
try {
executablePath = await prepareChromeExecutable(executablePath);
log.info("Chromium", "Testing Chromium executable: " + executablePath);
log.info("chromium", "Testing Chromium executable: " + executablePath);
const browser = await chromium.launch({
executablePath,

View File

@ -29,7 +29,7 @@ class SNMPMonitorType extends MonitorType {
error ? reject(error) : resolve(varbinds);
});
});
log.debug("monitor", `SNMP: Received varbinds (Type: ${snmp.ObjectType[varbinds[0].type]} Value: ${varbinds[0].value})`);
log.debug(this.name, `SNMP: Received varbinds (Type: ${snmp.ObjectType[varbinds[0].type]} Value: ${varbinds[0].value})`);
if (varbinds.length === 0) {
throw new Error(`No varbinds returned from SNMP session (OID: ${monitor.snmpOid})`);