Skip to main content

Config

The Config bot module allows you to read configuration files within LAMbots and Moobots.

It retrieves valid JSON configuration files found in $MOOGSOFT_HOME/config and performs a direct read from the file system before delivering the JSON Object to the calling bot. The module is available for all bots but can only be used for reading and storing global configuration files.

Before you begin

Before you use the Config bot module, ensure you have met the following requirements:

  • The configuration file is in valid JSON.

  • The configuration file is in $MOOGSOFT_HOME/config.

  • The configuration is present on the file system as the process running the bot.

Best practice

Follow these guidelines when using the Config bot module:

  • Use the module within the constraints of the OnLoad function.

  • Note that making multiple calls to the module may impact the performance of the bot.

  • Keep custom configuration files in a subdirectory of $MOOGSOFT_HOME/config and name them appropriately.

  • Comment custom configuration files extensively so other users can understand the context of their use.

Error reporting

The following error messages are returned if the configuration file cannot be opened, the contents returned are null or if the JSON is invalid:

INFO :[CJSONCodec.java]:813 +|java.io.FileNotFoundException: /export/src/incident/build/config/bad.conf (No such file or directory): Unable to open file /export/src/incident/build/config/bad.conf|+

WARN :[CJSONCodec.java]:105 +|Failed to parse file /export/src/incident/build/config/bad.conf, returned null contents|+

WARN :[CConfigModule.java]:112 +|File [/export/src/incident/build/config/bad.conf] is either missing, unreadable or is not valid JSON.|+

Examples

If you want to create a URL that links to Moogsoft Enterprise Situations, you can use the Config bot module to dynamically retrieve the base URL of the Moogsoft Enterprise instance from servlets.conf. For example:

var config = MooBot.loadModule('Config');
...
var servletsConf = config.getConfig('servlets.conf');
if (servletsConf) {
    moogURL = servletsConf.webhost;
}