Moogsoft Docs



The Events MooBot module allows you to make a MooBot driven by the occurrence of Events by defining the type of Event that interests the MooBot.

The Events module is available to load into any standard MooBot.

To use , at the top of a MooBot js file , define a new global object events to load the Events module:

var events = MooBot.loadModule('Events');


  • events.onEvent

The Events module has only one method, onEvent . This method points the MooBot to a supplied JavaScript function, which is called when a specified Event type occurs.

The parameters to the called function depend on the type of Event that you are listening for.

In a MooBot, this method is typically the last line in a script.

The type of Event adaptor chosen is specific to the type of MooBot you are building.

Reference Guide



Takes the name of a valid JavaScript function in a MooBot and also an Event code (from the Constants module eventType ), and returns an Event adaptor object

Request Arguments

Name Type Description
String The name of a valid JavaScript function in the MooBot that is called when the Event arrives
CEvent eventType Event code that specifies what type of Event the MooBot is listening for. It is typically from the Constants module

Return Parameter

Name Type Description
Object An Event adaptor object. Made active with the listen () function in-line to listen for the Event type


For the AlertBuilder MooBot:


When the Moolet starts and loads this Events MooBot, its JavaScript file executes, initializing the MooBot to respond in an event-driven way to Events arriving.

newEvent Javascript function

The format of the function newEvent (which is called when you get an Event), is as follows:

function newEvent

function newEvent()

Request Argument

Name Type Description
CEvent object An object that encapsulates all the data for the Event from the bus, and allows you to forward the Event to the bus, using the CEvent forward method detailed below

CEvent forward methods

You can emulate MoogDb behaviour by running the MoogDb.V2 MooBots.

For example, the alert.forward(this) line will send an Alert onto the Moolets specified in the appropriate process_output_of block within moog_farmd.conf

You could instead remove the process_output_of lines from the AlertRulesEngine / Sigaliser / Cookbook / Speedbird / Nexus Moolets and explicitly send Events / Alerts / Situations on within the MooBot code using (as an example)


The advantage of this approach is that Alerts / Situations can be forwarded to different AlertRulesEngines / Sigalisers dynamically in the MooBots (for example based on the value of the source field)

CEventAdaptor auxiliary object

This object is a utility class used by the Events module to allow for the programmatic activation of Event listening. It has one method:



Starts the Event adaptor listening, which then calls the specified function when an Event occurs

Request Argument


Return Parameter

Void - no value returned

CEvent auxiliary object

This object encapsulates a generic MooMS bus Event object, and the contents of it are specific to the Event type it represents. You can however access the key-value pairs contained in the object, and also set the values. Its methods include:



Returns true if the Event contains a value stored at the key name .

Request Argument

Name Type Description
String The name of the key being queried

R eturn Parameter

Type Description
Boolean true if the Event has a field called name , otherwise false



Associates the specified value with the specified name in the Event.

Previous key mapping has the old value replaced.

Request Argument

Name Type Description
String The key with which the specified value is to be associated
Object The value associated with the key

R eturn Parameter

Type Description
Indicates if the operation was successful: true = success, false = fail



Returns the object stored at the key name .

Request Argument

Name Type Description
String The name of the key to return the object from

R eturn Parameter

Type Description
A Javascript object containing what is at the key name



Compatibility with MoogDb and MoogDb.V2
Methods and auxiliary objects listed here are compatible with the MoogDb.V2 module