|
|
@ -10,7 +10,7 @@ class MqttMonitorType extends MonitorType {
|
|
|
|
* @inheritdoc
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
async check(monitor, heartbeat, server) {
|
|
|
|
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,
|
|
|
|
port: monitor.port,
|
|
|
|
username: monitor.mqttUsername,
|
|
|
|
username: monitor.mqttUsername,
|
|
|
|
password: monitor.mqttPassword,
|
|
|
|
password: monitor.mqttPassword,
|
|
|
@ -24,7 +24,7 @@ class MqttMonitorType extends MonitorType {
|
|
|
|
|
|
|
|
|
|
|
|
if (monitor.mqttCheckType === "keyword") {
|
|
|
|
if (monitor.mqttCheckType === "keyword") {
|
|
|
|
if (receivedMessage != null && receivedMessage.includes(monitor.mqttSuccessMessage)) {
|
|
|
|
if (receivedMessage != null && receivedMessage.includes(monitor.mqttSuccessMessage)) {
|
|
|
|
heartbeat.msg = `Topic: ${monitor.mqttTopic}; Message: ${receivedMessage}`;
|
|
|
|
heartbeat.msg = `Topic: ${messageTopic}; Message: ${receivedMessage}`;
|
|
|
|
heartbeat.status = UP;
|
|
|
|
heartbeat.status = UP;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw Error(`Message Mismatch - Topic: ${monitor.mqttTopic}; Message: ${receivedMessage}`);
|
|
|
|
throw Error(`Message Mismatch - Topic: ${monitor.mqttTopic}; Message: ${receivedMessage}`);
|
|
|
@ -103,7 +103,7 @@ class MqttMonitorType extends MonitorType {
|
|
|
|
client.on("message", (messageTopic, message) => {
|
|
|
|
client.on("message", (messageTopic, message) => {
|
|
|
|
client.end();
|
|
|
|
client.end();
|
|
|
|
clearTimeout(timeoutID);
|
|
|
|
clearTimeout(timeoutID);
|
|
|
|
resolve(message.toString("utf8"));
|
|
|
|
resolve([ messageTopic, message.toString("utf8") ]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|