mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
Add HIDE_LOG and catch error if cannot subscribe topic
This commit is contained in:
parent
083e8355b7
commit
30e113755e
4 changed files with 83 additions and 4 deletions
|
@ -90,6 +90,9 @@ exports.pingAsync = function (hostname, ipv6 = false) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
|
|
||||||
|
log.debug("mqtt", `Topic: ${topic}`);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { port, username, password, interval = 20 } = options;
|
const { port, username, password, interval = 20 } = options;
|
||||||
|
|
||||||
|
@ -114,7 +117,12 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) {
|
||||||
|
|
||||||
client.on("connect", () => {
|
client.on("connect", () => {
|
||||||
log.debug("mqtt", "MQTT subscribe topic");
|
log.debug("mqtt", "MQTT subscribe topic");
|
||||||
client.subscribe(topic);
|
|
||||||
|
try {
|
||||||
|
client.subscribe(topic);
|
||||||
|
} catch (e) {
|
||||||
|
reject(new Error("Cannot subscribe topic"));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("error", (error) => {
|
client.on("error", (error) => {
|
||||||
|
@ -256,7 +264,7 @@ const parseCertificateInfo = function (info) {
|
||||||
const existingList = {};
|
const existingList = {};
|
||||||
|
|
||||||
while (link) {
|
while (link) {
|
||||||
log.debug("util", `[${i}] ${link.fingerprint}`);
|
log.debug("cert", `[${i}] ${link.fingerprint}`);
|
||||||
|
|
||||||
if (!link.valid_from || !link.valid_to) {
|
if (!link.valid_from || !link.valid_to) {
|
||||||
break;
|
break;
|
||||||
|
@ -271,7 +279,7 @@ const parseCertificateInfo = function (info) {
|
||||||
if (link.issuerCertificate == null) {
|
if (link.issuerCertificate == null) {
|
||||||
break;
|
break;
|
||||||
} else if (link.issuerCertificate.fingerprint in existingList) {
|
} else if (link.issuerCertificate.fingerprint in existingList) {
|
||||||
log.debug("util", `[Last] ${link.issuerCertificate.fingerprint}`);
|
log.debug("cert", `[Last] ${link.issuerCertificate.fingerprint}`);
|
||||||
link.issuerCertificate = null;
|
link.issuerCertificate = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
@ -292,7 +300,7 @@ exports.checkCertificate = function (res) {
|
||||||
const info = res.request.res.socket.getPeerCertificate(true);
|
const info = res.request.res.socket.getPeerCertificate(true);
|
||||||
const valid = res.request.res.socket.authorized || false;
|
const valid = res.request.res.socket.authorized || false;
|
||||||
|
|
||||||
log.debug("util", "Parsing Certificate Info");
|
log.debug("cert", "Parsing Certificate Info");
|
||||||
const parsedInfo = parseCertificateInfo(info);
|
const parsedInfo = parseCertificateInfo(info);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
32
src/util.js
32
src/util.js
|
@ -54,7 +54,39 @@ function debug(msg) {
|
||||||
}
|
}
|
||||||
exports.debug = debug;
|
exports.debug = debug;
|
||||||
class Logger {
|
class Logger {
|
||||||
|
constructor() {
|
||||||
|
/**
|
||||||
|
* UPTIME_KUMA_HIDE_LOG=debug_monitor,info_monitor
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* [
|
||||||
|
* "debug_monitor", // Hide all logs that level is debug and the module is monitor
|
||||||
|
* "info_monitor",
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
this.hideLog = {
|
||||||
|
info: [],
|
||||||
|
warn: [],
|
||||||
|
error: [],
|
||||||
|
debug: [],
|
||||||
|
};
|
||||||
|
if (typeof process !== "undefined" && process.env.UPTIME_KUMA_HIDE_LOG) {
|
||||||
|
let list = process.env.UPTIME_KUMA_HIDE_LOG.split(",").map(v => v.toLowerCase());
|
||||||
|
for (let pair of list) {
|
||||||
|
// split first "_" only
|
||||||
|
let values = pair.split(/_(.*)/s);
|
||||||
|
if (values.length >= 2) {
|
||||||
|
this.hideLog[values[0]].push(values[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.debug("server", "UPTIME_KUMA_HIDE_LOG is set");
|
||||||
|
this.debug("server", this.hideLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
log(module, msg, level) {
|
log(module, msg, level) {
|
||||||
|
if (this.hideLog[level] && this.hideLog[level].includes(module)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
module = module.toUpperCase();
|
module = module.toUpperCase();
|
||||||
level = level.toUpperCase();
|
level = level.toUpperCase();
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|
39
src/util.ts
39
src/util.ts
|
@ -59,7 +59,46 @@ export function debug(msg: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UPTIME_KUMA_HIDE_LOG=debug_monitor,info_monitor
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* [
|
||||||
|
* "debug_monitor", // Hide all logs that level is debug and the module is monitor
|
||||||
|
* "info_monitor",
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
hideLog : any = {
|
||||||
|
info: [],
|
||||||
|
warn: [],
|
||||||
|
error: [],
|
||||||
|
debug: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
if (typeof process !== "undefined" && process.env.UPTIME_KUMA_HIDE_LOG) {
|
||||||
|
let list = process.env.UPTIME_KUMA_HIDE_LOG.split(",").map(v => v.toLowerCase());
|
||||||
|
|
||||||
|
for (let pair of list) {
|
||||||
|
// split first "_" only
|
||||||
|
let values = pair.split(/_(.*)/s);
|
||||||
|
|
||||||
|
if (values.length >= 2) {
|
||||||
|
this.hideLog[values[0]].push(values[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.debug("server", "UPTIME_KUMA_HIDE_LOG is set");
|
||||||
|
this.debug("server", this.hideLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log(module: string, msg: any, level: string) {
|
log(module: string, msg: any, level: string) {
|
||||||
|
if (this.hideLog[level] && this.hideLog[level].includes(module)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
module = module.toUpperCase();
|
module = module.toUpperCase();
|
||||||
level = level.toUpperCase();
|
level = level.toUpperCase();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue