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 is relevant to the Moobot.

The Events module is available to load into any standard Moobot. To use, define a new global object events at the top of a Moobot JavaScript file:

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

Reference Guide

The following methods, functions and auxiliary objects are applicable to the Events Moobot.


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

onEvent method

The Events module has a single method, onEvent. It t akes the name of a Moobot JavaScript function and an event code and returns an event adaptor object. It is called when a specified event type occurs. The parameters 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.

Request Arguments

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

Return Parameter

Type Description
Object An event adaptor object. Made active with the listen function in-line to listen for the event type.


An example onEvent method for the Alert Builder Moolet is as follows:


This example:

  • Calls the newEvent JavaScript function.

  • Defines the event type "Event" (from the Constants module), which responds to events put on the Message Bus by a LAM.

  • Calls the listen method to listen for the event type.

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 as they arrive.

newEvent function

A function that is called when an event arrives.

Request Argument

Name Type Description
event CEvent Object An object that encapsulates all the data for the event from the Message 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 behavior by running the MoogDb.V2 Moobots. For example, the alert.forward(this) command sends an alert to the Moolets specified in the appropriate "process output of" block within the Moogfarmd configuration file.

You could instead remove the "process output of" properties from the Alert Rules Engine, Sigaliser, Cookbook or Speedbird Moolets and explicitly send events, alerts and Situations within the Moobot code. For example:


The advantage of this approach is that you can forward alerts and Situations to different Alert Rules Engines or Sigalisers dynamically in the Moobots, for example based on the value of the source file.

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 a single method, listen.


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

Request Argument


Return Parameter


CEvent auxiliary object

This object encapsulates a generic Message 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 are contains, set and value.


Returns true if the event contains a value stored for the specified key.

Request Argument

Name Type Description
name String The name of the key to query.

Return Parameter

Type Description
Boolean True if the event contains a field with the specified name, otherwise false.


Associates a specified value with the specified event name. An existing key mapping is replaced with the supplied value.

Request Argument

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

Return Parameter

Type Description
Boolean True if the operation was successful, otherwise false.


Returns the object stored at the specified key name.

Request Argument

Name Type Description
name String The name of the key for which to return the object.

Return Parameter

Type Description
Object A JavaScript object containing the data stored at the specified key.