Skip to main content

Moolet Informs

The Moolet Informs module enables the exchange of messages between Moolets. You can configure a Moolet to update other Moolets. For example, after you label some alerts you can configure the module to inform the ticketing Moolet to update the severity of a ticket, based on the new label.

To use Moolet Informs, you need:

  • A Moolet and associated Moobot to send inform messages from.

  • One or more Moolets to receive the inform messages. These are your "targets".

Load the module

The Moolet Informs module is available to load into any standard Moobot. To load it, define a new global variable at the top at the top of the Javascript file of the Moobot associated with the Moolet you want to send messages from. For example:

var mooletInforms = MooBot.loadModule('MooletInforms');

Configure the Moobot as outlined below.

Configure the module

To configure the Moolet Informs module:

  1. Create the Moolet Inform using the create method as follows, passing the target Moolets that receive messages from this source:

    var inform = mooletInforms.create("AlertRulesEngine", "Cookbook");

    Or, you can choose not to specify the target Moolets in this step:

    var inform = mooletInforms.create();
  2. Add values to the inform using one or more of the following:

    • inform.setSubject: Subject of the inform message. You can use this to enable a different workflow within the target Moobot. An appropriate event handler line is needed in the receiving moobot ot process the Inform if a subject is defined.

    • inform.setPayload: Any CEvent object. See Events for more information.

    • inform.setDetails: Details of any other data you want to send as a JSON object.

  3. If you did not specify the target Moolets previously, specify them now:

    • inform.setTarget: List of target Moolets to receive messages.

  4. You can configure message sending in two ways. If you have already set your targets:

    inform.send();

    If you have not set your targets, include them in the method call:

    inform.send("AlertRulesEngine", "Cookbook");
  5. Edit the configuration file for each target Moolet and add an event handler to listen for the Inform messages:

    events.onEvent("informReceive", constants.eventType("mooletInforms.ExampleMoolet")).listen();
  6. The listening target Moolet can access the data in two ways. You can use the getSubject, getPayload and getDetails methods:

    function informReceive(inform) 
    {
        var subject = inform.getSubject();
        var payload = inform.getPayload();
        var details = inform.getDetails();
        logger.warning("Received Moolet Inform. Subject [" + subject + "] Payload [" + payload + "] Details [" + details + "]");
    }

    Alternatively, you can use the value method:

    function informReceive(inform) 
    {
        var subject = inform.value("subject");
        var payload = inform.value("payload");
        var details = inform.value("details");
        logger.warning("Received Moolet Inform. Subject [" + subject + "] Payload [" + payload + "] Details [" + details + "]");
    }
  7. You can configure the Moolet to call a specific method for different subjects in the inform messages. For example you can configure a Remedy Moolet to listen for a specific subject (ticketCreate) in the inform message and route the event to a function (createNewTicket):

    events.onEvent("createNewTicket", constants.eventType("mooletInforms.RemedyMoolet.ticketCreate")).listen();

After you have completed your configuration, inform messages are sent to your target Moolets which will call any methods you have added.

Method reference

The Moolet Informs module uses the following methods.

create

Creates a Moolet inform message. You can choose to select one or more Moolet targets to receive the messages, or you can leave the method empty.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

targets

String

No

A single Moolet or comma separated list of Moolets to target.

Response

The method returns the following parameter.

Type

Description

Object

A Moolet inform Java object.

Example

The following example uses the create method to set MaintenanceWindowManager and AlertRulesEngine as targets:

var inform = mooletInforms.create("MaintenanceWindowManager", "AlertRulesEngine");

setSubject

Sets the subject for Moolets to listen for on the Message Bus. If a subject is defined, the listening/receiving moolet must have an appropriate event handler line defined with the subject specified as the last part of the eventType string. For example: mooletInforms.<recievingMooletName>.<subject>

If multiple subjects are defined, then multiple event handler lines can be defined to allow informs with different subjects to be handled by different methods in the receiving moobot.

Request arguments

The method takes the following arguments:

Name

Type

Required

Description

Subject

String

Yes

Subject the Moolets listen for on the Message Bus.

Response

None.

Example

The following example uses the setSubject method to set the subject "subTopic":

inform.setSubject("subTopic");

setPayload

Sets the payload to a CEvent object. See Events for more information.

Request arguments

The method takes the following argument:

Name

Type

Required

Description

Payload

CEvent

Yes

A CEvent object that has been passed into the Moobot from the pipeline, or has been retrieved from MoogDb.

Response

None.

Example

The following example uses the setPayload method to set the payload to the "event" CEvent:

inform.setPayload(event);

setDetails

Sets any other details to send in the Moolet Inform message.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

setDetails

NativeObject

Yes

A JSON object containing details to send in the message.

Response

None.

Example

The following example uses the setDetails method to send signature, description and source details in the message.

inform.setDetails({"signature":"Loss of Signal","description":"Loss of Signal","source":"S-DF_P2_1"});

setTarget

Sets the target Moolets to receive the Moolet Inform messages. Use this method if you did not set the target Moolets with the create method.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

targets

String

Yes

A single Moolet or comma separated list of Moolets to target.

Response

None.

Example

The following example uses the setTarget method to set AlertRulesEngine and Cookbook as targets:

inform.setTarget("AlertRulesEngine", "Cookbook");

send

Sends the Moolet Informs messages to the target Moolets.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

targets

String

No

A single Moolet or comma separated list of Moolets to target.

Response

None.

Example

The following example uses the send method to send messages to the Cookbook:

inform.send("Cookbook");

Example

The following example uses the Moolet Inform module to send a signature, description and source to the Cookbook Moolet:

var mooletInforms = MooBot.loadModule('MooletInforms');
var inform = mooletInforms.create();
inform.setSubject("subTopic");
inform.setPayload(event);
inform.setDetails({"signature":"Loss of Signal","description":"Loss of Signal","source":"S-DF_P2_1"});
inform.send("Cookbook");

Example configuration in the target/listening Moolet:

events.onEvent("handleEvent", constants.eventType("mooletInforms.EmptyMoolet.subTopic")).listen();