From a8b8a21f4c0493c5af6c84d57a248b41b4f998fd Mon Sep 17 00:00:00 2001 From: Eric Duminil Date: Sun, 1 Dec 2024 21:24:21 +0100 Subject: [PATCH] Write MQTT published topic in message So that when wildcards for monitoring are used, the full published topic is displayed. --- server/monitor-types/mqtt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/monitor-types/mqtt.js b/server/monitor-types/mqtt.js index 2673e8e2f..7b71fbdcc 100644 --- a/server/monitor-types/mqtt.js +++ b/server/monitor-types/mqtt.js @@ -10,7 +10,7 @@ class MqttMonitorType extends MonitorType { * @inheritdoc */ async check(monitor, heartbeat, server) { - const receivedMessage = await this.mqttAsync(monitor.hostname, monitor.mqttTopic, { + const [ messageTopic, receivedMessage ] = await this.mqttAsync(monitor.hostname, monitor.mqttTopic, { port: monitor.port, username: monitor.mqttUsername, password: monitor.mqttPassword, @@ -24,7 +24,7 @@ class MqttMonitorType extends MonitorType { if (monitor.mqttCheckType === "keyword") { if (receivedMessage != null && receivedMessage.includes(monitor.mqttSuccessMessage)) { - heartbeat.msg = `Topic: ${monitor.mqttTopic}; Message: ${receivedMessage}`; + heartbeat.msg = `Topic: ${messageTopic}; Message: ${receivedMessage}`; heartbeat.status = UP; } else { throw Error(`Message Mismatch - Topic: ${monitor.mqttTopic}; Message: ${receivedMessage}`); @@ -103,7 +103,7 @@ class MqttMonitorType extends MonitorType { client.on("message", (messageTopic, message) => { client.end(); clearTimeout(timeoutID); - resolve(message.toString("utf8")); + resolve([ messageTopic, message.toString("utf8") ]); }); });