Skip to content

MQTT Event

Event that fires when the server receives an MQTT message.

Event name

mqtt

Request

cn.emit('add-topics', 'mqtt')
cn.emit('remove-topics', 'mqtt')

Response

Response contains the Event Log entry.

Field Type Description
_id String ID of the entry.
type Integer Message type. 1 for SNMP Trap, 2 for MQTT message.
timestamp Integer Timestamp of when the MQTT message was sent.
payload Object MQTT message.
payload.topic String MQTT topic.
payload.message String MQTT message.
entity Array<Object> List of entities that the MQTT message belongs to.
entity.entityId String ID of the entity.
entity.entityType Integer Type of the entity. 1 is an Object, 2 is a Link.
entity.entityName String Name of the entity.

Example

Request

const comet = require('socket.io-client');

// Comet settings
const COMET_CONNECT_TIMEOUT = 5000;
const sessionId = "..."
const conf = {
    cometHost: 'https://example.com',
    cometPort: '1234',
};

const url = `${conf.cometHost}` + (conf.cometPort ? `:${conf.cometPort}` : '');
const cn = comet.connect(url, {
    query: { forceNew: true, sessionId },
    timeout: COMET_CONNECT_TIMEOUT,
});

cn.emit('add-topics', 'mqtt');

cn.on('mqtt', msg => {
    console.log(msg);
});

Response

{
    "_id":"636cd525eb2070485dd03e6b",
    "type":2,
    "timestamp":1668076837571,
    "payload":{
        "topic":"test",
        "message":"test"
    },
    "entity":[
        {
            "entityId":"6081971e14879f73e96e494b",
            "entityType":1,
            "entityName":"qtt"
        },
        {
            "entityId":"5c5abcbfd75610326dd80248",
            "entityType":1,
            "entityName":"Host"
        }
    ]
}