Moogsoft Docs

Node.js

To integrate with your Node.js app, install the node-mood package and use the API to send data to the Node.js integration. This integration requires that you have working knowledge Node.js and how to write JavaScript code . See the Node.js documentation for more details.

Before You Begin

The Node.js integration has been validated with Node.js v. 1.6. Before you start to set up your integration, ensure you have met the following requirements:

  • You have access to the source code and can rebuild your Node.js app.
  • Your Node.js app can make requests to external endpoints over port 443.

Configure the Node.js Integration

Configure the Node.js integration in Moogsoft AIOps as follows:

  1. Navigate to the Integrations tab.
  2. Click Node.js in the Monitoring section.
  3. Follow the instructions to create an integration name.


Add Event Reporting to Your Node.js App

The node-moog module provides an API that enables you to create events in your Node.js app and send them directly to the Node.js integration.

Use the Node.js package manager to install the node-moog module:

npm install node-moog

The node-moog module provides two objects for you to manage sending events:

  • moogRest lets you connect the Node.js integration and submit event data
  • moogEvent is an optional event template you can use to format your event data

moogRest

Connect to the Node.js integration and submit event data to the integration.

Create a connection

moogRest(object) :  Initialize a connection to the Node.js integration based upon the information contained in a JSON formatted object as follows:

Property Value
url

<your Node.js integration URL>

For example: https://example.moogsoftaiops.com/events/nodejs_nodejs1

authUser

Username generated in the Moogsoft AIOps UI

authPass

Password generated in the Moogsoft AIOps UI

certFile
Path to the server certificate
caFile
Path to the client certificate

For example:

var moog = require('node-moog');

// Set the connection options for your Node.js integration.
var options = {'url':'https://aiops.example.com/events/nodejs_nodejs1',
	'authUser':'nodejs',
	'authPass':'mysecret',
	'certFile' : '../ssl/server.crt',
	'caFile' : '../ssl/client.crt'
};

// Initialize the the connection.
var moogRest = moog.moogREST(options);


Submit event data

moogRest.sendEvent(moogEvent,callback) : Pass an event in JSON format or an array of events to the Node.js integration. There is an event emitter and will currently provide two events: ok and error.

Parameter Description
moogEvent JSON object or an array of JSON objects that represent events to report
callback Function to handle the HTTP response

For example:

// Create a proforma event.
var moogEvent = new moog.MoogEvent();
moogEvent.description = 'A demo event';


// Send the event to the Node.js integration.
// The callback function is defined inline.
moogRest.sendEvent(moogEvent, function (res, rtn) {
    if (rtn == 200) {
        console.log('moogRest message sent, return code: ' + rtn);
        console.log('moogRest result: ' + res.message);
        //process.exit(1);
    } else {
        console.log('moogRest - ' + rtn);
        console.log('moogRest - ' + res);
        process.exit(1);
    }
});

MoogEvent

Create and populate events to send to the Node.js integration.

Create an event

MoogEvent(mEvent) : Initialize an event object. mEvent is an optional default event template. When you create an event using the proforma, you can pass a partial MoogEvent. The module provides default vaules for any properties without values.

Property Type Description
signature String Used to identify the event. Usually source:class:type.
source_id String Unique identifier for the source machine.
external_id String Unique identifier for the event source.
manager String General identifier of the event generator or intermediary.
source String Hostname or FQDN of the source machine that generated the event.
class String Level of classification for the event. Follows hierarchy class then type.
agent_location String Geographical location of the agent that created the event.
type String Level of classification for the event. Follows hierarchy class then type.
severity Int Severity level of the event from 0-5 (clear - critical).
description String Text description of the event.
first_occurrred Epoch int Timestamp of the first occurance of the event in Unix epoch time.
agent_time Epoch int Timestamp of the current occurance of the event in Unix epoch time.

For example to create a new event and edit the value of the description:

var moog = require('node-moog');
var MoogEvent = moog.MoogEvent;

// Initialize an event.
myEvent = new MoogEvent();
//Change the value of an event property.
myEvent.description = 'My new description';

Example

The following example demonstrates how to send a single event to the Node.js integration:

var moog = require('node-moog');

// Set the connection options for your Node.js integraion.
var options = {'url':'https://aiops.example.com/events/nodejs_nodejs1',
    'authUser':'nodejs',
    'authPass':'CUKeB3XhDr1MaypG',
    'certFile' : './ssl/certificate.pem',
    'caFile' : './ssl/certificate.key'
};

// Initialize the REST connection.
var moogRest = moog.moogREST(options);

// Create a proforma event.
var moogEvent = new moog.MoogEvent();


// Change the event description.
moogEvent.description = 'Demo event.';
console.log(moogEvent)

// Send the event to the Node.js integration.
// The callback processes the HTTP response from the integration
// and prints it to the console.
moogRest.sendEvent(moogEvent, function (res, rtn) {
    if (rtn == 200) {
        console.log('moogRest message sent, return code: ' + rtn);
        console.log('moogRest result: ' + res.message);
        //process.exit(0);
    } else {
        console.log('moogRest - ' + rtn);
        console.log('moogRest - ' + res);
        process.exit(1);
    }
});