Node.js
Node.js is a JavaScript runtime environment that executes JavaScript code outside of a browser. To integrate with a Node.js app, you can install the node-moog module and use the API to send data to the Node.js integration.
Refer to the LAM and Integration Reference to see the integration's default properties. When you use the integrations UI, you can only configure the visible properties.
If you want to implement a more complex Node.js LAM with custom settings, see Configure the Node.js LAM.
See the Node.js documentation for information on Node.js components.
Before You Begin
The Node.js integration has been validated with Node.js v1.6. Before you start to set up your integration, ensure you have met the following requirements:
You have a working knowledge of Node.js and can write JavaScipt code.
You have access to the Node.js source code and the ability and permissions to rebuild your Node.js app.
Your Node.js app can make requests to external endpoints over port 443. This is the default.
Configure the Node.js Integration
To configure the Node.js integration:
Navigate to the Integrations tab.
Click Node.js in the Monitoring section.
Provide a unique integration name. You can use the default name or customize the name according to your needs.
Set a Basic Authentication username and password.
Configure 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 module:
npm install node-moog
The module provides two objects to manage sending events:
moogRest
: Connects the Node.js integration and submits event data.moogEvent
: An optional event template you can use to format your event data.
Create a connection using moogRest
moogRest(object)
initializes a connection to the Node.js integration based upon the information contained in a JSON formatted object as follows:
Property | Value |
---|---|
| <your Node.js integration URL> For example: https://example.Moogsoft.com/events/nodejs_nodejs1 |
| Username generated in the Moogsoft Onprem UI. |
| Password generated in the Moogsoft Onprem UI. |
| Path to the server certificate. |
| 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 using moogRest
moogRest.sendEvent(moogEvent,callback)
passes an event in JSON format or an array of events to the Node.js integration. There is an event emitter that provides two events: ok and error.
Parameter | Description |
---|---|
| JSON object or an array of JSON objects that represent events to report |
| 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); } });
Create an event using moogEvent
moogEvent(mEvent)
initializes 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 values for any properties without values.
Property | Type | Description |
---|---|---|
| String | Identifies the event. Usually source:class:type. |
| String | Unique identifier for the source machine. |
| String | Unique identifier for the event source. |
| String | General identifier of the event generator or intermediary. |
| String | Hostname or FQDN of the source machine that generated the event. |
| String | Level of classification for the event. Follows hierarchy class then type. |
| String | Geographical location of the agent that created the event. |
| String | Level of classification for the event. Follows hierarchy class then type. |
| Int | Severity level of the event from 0-5 (clear - critical). |
| String | Text description of the event. |
| Epoch int | Timestamp of the first occurrence of the event in Unix epoch time. |
| Epoch int | Timestamp of the current occurrence 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';
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); } });