diff --git a/server/monitor-types/mqtt.js b/server/monitor-types/mqtt.js index f1c1ad23c..f6b3cf8a8 100644 --- a/server/monitor-types/mqtt.js +++ b/server/monitor-types/mqtt.js @@ -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(); diff --git a/server/monitor-types/postgres.js b/server/monitor-types/postgres.js index 6d6940191..fb6cc9b0d 100644 --- a/server/monitor-types/postgres.js +++ b/server/monitor-types/postgres.js @@ -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); }); diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index 07b6c8aac..12eb50de5 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -63,7 +63,6 @@ if (process.platform === "win32") { * @returns {Promise} 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} 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, diff --git a/server/monitor-types/snmp.js b/server/monitor-types/snmp.js index a1760fa3d..e6ba94cca 100644 --- a/server/monitor-types/snmp.js +++ b/server/monitor-types/snmp.js @@ -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})`);