Incident Count Event
Event that fires when the number of active Incidents in the system changed.
Request
-
Subscribe
-
Unsubscribe
cn.emit('add-topics', 'incident-count')
cn.emit('remove-topics', 'incident-count')
Examples
This example gets the number of active incidents using the Get Number Of Active Incidents request when it receives the incident-count
event.
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,
});
// Subscribe to the incident-count topic
cn.emit('add-topics', 'incident-count');
// Receive the response
cn.on('incident-count', msg => {
// Get the number of active incidents
let path = "/node/api/incidents/active/count";
let options = {
"method": "GET",
"hostname": saymonHostname,
"headers": {
"Cookie": "sid=" + sessionId
},
"path": path
};
let req = http.request(options, function (res) {
let chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
let body = Buffer.concat(chunks);
console.log('Active Incident Count: ' + body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
req.end();
});