diff --git a/server/model/monitor.js b/server/model/monitor.js index c31285725..52e1da34d 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -87,6 +87,7 @@ class Monitor extends BeanModel { notificationIDList, tags: tags, mqttUsername: this.mqttUsername, + mqttPassword: this.mqttPassword, mqttTopic: this.mqttTopic, mqttSuccessMessage: this.mqttSuccessMessage }; @@ -400,20 +401,13 @@ class Monitor extends BeanModel { throw new Error("Server not found on Steam"); } } else if (this.type === "mqtt") { - try { - bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, { - mqttPort: this.port, - mqttUsername: this.mqttUsername, - mqttPassword: this.mqttPassword, - interval: this.interval, - }); - bean.status = UP; - } catch (error) { - if (error.message !== "Timeout") { - bean.status = DOWN; - bean.msg = error.message; - } - } + bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, { + port: this.port, + username: this.mqttUsername, + password: this.mqttPassword, + interval: this.interval, + }); + bean.status = UP; } else { bean.msg = "Unknown Monitor Type"; bean.status = PENDING; diff --git a/server/util-server.js b/server/util-server.js index 7a14a23de..d0a932aaa 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -90,9 +90,6 @@ exports.pingAsync = function (hostname, ipv6 = false) { }; exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { - - log.debug("mqtt", `Topic: ${topic}`); - return new Promise((resolve, reject) => { const { port, username, password, interval = 20 } = options; @@ -104,7 +101,7 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { const timeoutID = setTimeout(() => { log.debug("mqtt", "MQTT timeout triggered"); client.end(); - reject("Timeout"); + reject(new Error("Timeout")); }, interval * 1000 * 0.8); log.debug("mqtt", "MQTT connecting"); @@ -116,9 +113,10 @@ exports.mqttAsync = function (hostname, topic, okMessage, options = {}) { }); client.on("connect", () => { - log.debug("mqtt", "MQTT subscribe topic"); + log.debug("mqtt", "MQTT connected"); try { + log.debug("mqtt", "MQTT subscribe topic"); client.subscribe(topic); } catch (e) { client.end();