Skip to main content

Constants

Each Moobot runs in its own thread and instances of Moobots are independent of each other. The Constants module enables you to share logic, states or flags between Moobots. You can build a key value dictionary mapping that is shared across Moobot instances.

There are many system wide defined Constants that are used in the Events module to define which event to listen for. See the event types table below for more information.

Load the module

The Constants module is available to load into any standard Moobot. To load it, define a new global variable at the top of the Moobot Javascript file. For example:

var constants = MooBot.loadModule('Constants');

Method reference

The Constants module uses the following methods.

put

Associated a specified value with a specified key. Replaces the mapping for an existing key.

Request arguments

The method takes the following arguments.

Name

Type

Description

key

String

The key to associate with the value.

value

Object

The value to associate with the key.

Response

None.

get

Retrieves the value mapped to a specified key.

Request arguments

The method takes the following arguments.

Name

Type

Description

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The value to which the key is mapped, or null if no mapping exists.

getCopy

Available in Moogsoft Enterprise v8.0.0.2. Retrieves the copy of a value mapped to a specified key

Request arguments

The method takes the following argumets:

Name

Type

Description

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The copy of value to which the key is mapped, or null if no mapping exists.

getCopy

Available in Moogsoft Enterprise v8.0.0.2. Retrieves the copy of a value mapped to a specified key. Given a namespace, retrieves the copy of a value mapped to a specified key within the namespace.

Request arguments

The method takes the following arguments:

Name

Type

Description

Namespace

String

Namespace for the constant. For example, Integration type.

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The copy of value to which the key is mapped, or null if no mapping exists.

Example

The following example demostrates how to return the object mapped to the config key in the "PayloadMacroMaps" namespace:

var payloadConfig = constants.getCopy("PayloadMacroMaps", "config");

contains

Returns a positive response if the module contains an object with the specified name.

Request argument

The method takes the following argument:

Name

Type

Description

name

String

The Object name.

Response

The method returns the following parameter:

Type

Description

Boolean

True if the module contains the specified object, otherwise false.

remove

Removes the value mapped to the specified key.

Request arguments

The method takes the following arguments:

Name

Type

Description

key

String

The key for which the value is to be removed.

Response

None.

eventType

Retrieves the value of a specified event type.

Request arguments

The method takes the following arguments:

Name

Type

Description

name

String

The name of the event type. See the list of event types in the table below.

Event types

You can use one of the following event types in the name argument:

Name

Passed Value

Description

E_LamEvent

"Event"/"Events"

Raw event from a LAM

E_NewAlert

"Alert"/"Alerts"

A new alert was created from an event.

E_AlertUpdate

"AlertUpdate"

An existing alert was updated (examples: severity changed, deduplication occurred).

E_CloseAlert

"AlertClose"

An existing alert was closed.

E_NewComment

"Comment"

A new comment was added into a Situation Room.

E_NewFeedback

"Feedback"

New feedback (a rating) was added to a Thread Entry in a Situation Room.

E_NewSig

"Sig"

A new Situation was created.

E_SigClose

"SigClose"

An existing Situation was Closed.

E_SigUpdate

"SigUpdate"

An existing Situation was updated (examples: alerts added, teams changed).

E_SigStatus

"SigStatus"

An existing Situation changed state (for example, set to Resolved).

E_SigAction

"SigAction"

A SituationAction message was generated, which contains details of the action. Possible messages include Situation updates, thread entry changes, situation merges, tool usage, user workflow changes, and other similar information.

E_ThreadEntry

"ThreadEntry"

An existing Thread Entry was updated (example: a comment was added).

E_NewThreadEntry

"NewThreadEntry"

A new Thread Entry was added to a Situation Room.

E_Summary

"Summary"

A System Summary event message was generated (example: containing total number of Events or Situations).

E_Invite

"Invitation"

A user was invited to a Situation.

E_User

"User"

Username

E_Unknown

"Unknown"

An uncategorized event (error condition)

Response

The method returns the following parameter:

Type

Description

CEvent

An object containing the value of the specified event type.

Examples

The following example in AlertBuilder.js shows the Constants module with two methods that allow you to post and retrieve values from a shared scratchpad.

var count=0 
constants.put("counter",count);

The variable count is set to 0 and stored using the label counter.

You can then retrieve a value by calling the get method and passing the name of the shared attribute, which is returned as a JavaScript local variable.

var count_val=constants.get("counter");
count_val++; 
constants.put("counter",count_val);
  • The get method takes the name of the shared attribute, "counter".

  • The variable count_val is incremented.

  • The put method takes the name of the variable to store, "counter", and the incremented value count_val.

If nothing is stored in counter, the Moobot returns null.

The following example passes the name of an event and returns a system wide constant that identifies that type of event when using the Events module.

constants.eventType("Event")