Incident Count Event

Event that fires when the number of active Incidents in the system changed.

Event name

incident-count

Request

  • Subscribe

  • Unsubscribe

cn.emit('add-topics', 'incident-count')
cn.emit('remove-topics', 'incident-count')

Response

Response contains the following fields:

Field Type Description

changed

Boolean

true if the number of incidents changed.

Example

{
  changed: true
}

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();
});

Response

Active Incident Count: 42
Active Incident Count: 41
Active Incident Count: 42
Active Incident Count: 43
Active Incident Count: 44