Moogsoft Docs

Events (MOOGDb only)

Note

Compatibility with MoogDb and MoogDb.V2

Methods and auxiliary objects listed here are compatible with the MoogDb module, which was removed in v4.1.14
Information here is provided for reference only
Those methods and auxiliary objects compatible with its replacement the MoogDb.V2 module

Description

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');

Method

  • 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

events.onEvent

events.onEvent()

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
functionName
String The name of a valid JavaScript function in the MooBot that is called when the Event arrives
type
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
CEventAdaptor
Object An Event adaptor object. Made active with the listen() function in-line to listen for the Event type

Example

For the AlertBuilder MooBot:

events.onEvent("newEvent",constants.eventType("Event")).listen();

When the Moolet starts and loads this Events MooBot, its JavaScript file executes, initialising 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 Arguments

Name Type Description
event
CEvent object An object that encapsulates all the data for the Event from the bus
response
CResponse object An object to communicate back to the Moolet. The Moolet uses this response to broadcast any updates, or any changes to the data structures on the MooMs bus

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:


listen

listen()

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

Request Argument

None.

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:

contains

contains()

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

Request Argument

Name Type Description
name
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


set

set()

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

Previous key mapping has the old value replaced.

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

R eturn Parameter

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


value

value()

Returns the object stored at the key name .

Request Argument

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

R eturn Parameter

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


CEvent auxiliary object

Note

Note

The following methods only apply to the MoogDb module, which is being deprecated


getJournalDetails

getJournalDetails()

Returns the details (if any) of the journaled operation for a Situation

Request Argument

Name Type Description
scope
Javascript object The MooBot context, provided by using this as a parameter

R eturn Parameter

Type Description
Object Javascript object containing the details of the journaled operation for a Situation
getCustomInfo

getCustomInfo()

Returns the custom information (if any) for an Alert or Situation.

Request Argument

Name Type Description
scope
Javascript object The MooBot context, provided by using this as a parameter

R eturn Parameter

Type Description
Object Javascript object containing the custom information

setCustomInfo

setCustomInfo()

Sets the custom information for an Alert or Situation

Request Arguments

Name Type Description
scope
Javascript object The MooBot context, provided by using this as a parameter
customInfoJS
Native object A Javascript object containing the custom information

R eturn Parameter

Void - no value returned


getCorrelationInfo...

getCorrelationInfo()

Returns the external service correlation_info (where this has been set) for a Situation.

Request Argument

Name Type Description
scope
Javascript object The MooBot context, provided by using this as a parameter

R eturn Parameter

Type Description
Object Javascript object containing the correlation_info


getSummaryData...

getSummaryData()

Returns the summary information from a statistics summary Event.

Request Argument

Name Type Description
scope
Javascript object The MooBot context, provided by using this as a parameter

R eturn Parameter

Type Description
Object Javascript object containing the summary information

CResponse auxiliary object

Note

Note

The following methods only apply to the MoogDb module, which is being deprecated


message

message()

Object to broadcast on

Request Argument

Name

Type

Description

msg

CEvent

Object to broadcast on

Return Parameter

Void - no value returned


topic

topic()

Topic to broadcast message on

Request Argument

Name Type Description
topic
String The topic name

Return Parameter

Void - no value returned

output

output()

Freeform message to attach

Request Argument

Name Type Description
txt
String The message as a text string

Return Parameter

Void - no value returned


retcode

retcode()

The retcode value must be >= 0 for a message to be sent.

Request Argument

Name Type Description
code
Number Must be >= 0 for a message to be sent

Return Parameter

Void - no value returned


doNotPropagate

doNotPropagate()

Indicates that no propagation is needed

Request Argument

None.

Return Parameter

Void - no value returned