Marid as a Web Server

Marid has an embedded web server and can be used to receive and process web requests (HTTP/HTTPS) from external systems such as Amazon SNS and Opsgenie.

669

Install Marid

Install Marid by referring to Overview & Installation document.

Configure Marid

Configuration parameters when using Marid to execute script via web requests are:

Script Directories (Will be referred as SCRIPTS_DIR in the rest of documentation)

  • On Linux: /var/opsgenie/marid/scripts
  • On Windows: <MARID_HOME>/scripts
    Script Executor Configuration
SettingDescriptionMandatoryDefault Value
maridKeyMarid key is used to authorize incoming script execution request and value can be any custom token. If not specified, no authorization will be done. If set, script url should be called with maridKey parameter and the value should be the same in configuration file.Nochangeme

HTTP Web Server Configuration Settings

SettingDescriptionMandatoryDefault Value
https.server.enabledEnable/disable HTTPS web serverYesfalse
https.server.hostHttps web server hostNo127.0.0.1
https.server.portHttps web server portNo8443
https.server.maxContentLengthMaximum HTTPS request content length for each request. Requests with higher content length will be discarded by the web server. (in bytes)No2000000
https.server.keystoreHTTPS server keystore file pathNo<MARID_HOME>/conf/.keystore
https.server.keyPasswordHTTPS server keystore file passwordNo123456
https.server.threadpool.sizeThe maximum number of simultaneous HTTP connectionNo100

🚧

Script reloading is automatically handled by Marid: After a script file is changed on the next run Marid will use the latest version regardless of Marid run state.

Marid executes the groovy or ruby scripts via web server /script/<script_file_name> URL. Marid executes the script file specified in URL for each web request. It will determine the script engine via script file extension.
For example if the URL is: https://<server>:<port>/script/HelloWorld.groovy then Groovy scripting engine executes the specified script. If maridKey configuration is set in configuration file, it should be passed with the HTTP request to successfully execute it. Following parameters are passed to script by default:

ParameterDescription
paramsThe map variable to access parameters passed by HTTP/S requests.
requestHTTP request object. HTTP request content, headers, method, remoteAddress can be accessed via this parameter.
responseHTTP response which will be returned. Response content, contentType and status code may be modified via this parameter.
confA reference to configuration file properties. Every configuration property is accessible via this parameter.
loggerLogging utility. All script logs will be written to script.log file in LOGS_DIR directory.
opsgenieThe variable to execute an operation on opsgenie server.
Please refer to Script Proxy for Marid documentation for a list of available operations.

🚧

Parameters are passed as global variables to Ruby scripts hence they should be accessed as $parameter_name. For example, logger parameter can be accessed as $logger in Ruby script.

Sample Usage:

Add following entry to configuration file:

sample.usage.prop1=prop1value

Set maridKey in configuration file as

maridKey=key1

URL to be Called via CURL

curl -XPOST 'http://<marid_server>:<marid_port>/script/HelloWorld.groovy?maridKey=key1&param1=value1&param2=value2' -d 'content data'

📘

Marid supports async script execution, which can be used by adding async=true http parameter in run script url.

Script File

<SCRIPTS_DIR>/HelloWorld.groovy

logger.warn(params.param1)
logger.warn(params.param2)
logger.warn(request.content)
logger.warn(conf["sample.usage.prop1"])
response.content = "Hello yourself"

Expected Output in Log File <LOGS_DIR>/Script.log

12/06/18 16:44:08.288 WARN: value1
12/06/18 16:44:08.288 WARN: value2
12/06/18 16:44:08.292 WARN: content data
12/06/18 16:44:08.298 WARN: prop1value

Expected curl Output

Hello yourself

Execute alert actions via Webhook

Opsgenie can call a web-accessible URL endpoint and pass action data (what's often referred to as webhooks). Webhook URL can be any platform, web server, etc. as long as the URL is accessible from the Web.

The webhook can be created at Opsgenie Webhook Integration page. For more information about Webhook Integration, see the support document.

1185

Thanks to the script execution capabilities described above, Marid can be used to receive and process the web request from Opsgenie. Marid has a built-in awareness of Opsgenie user actions, hence can be configured easily. When Marid is used to process Opsgenie user actions, the Webhook URL of the Webhook Integration should be:

https://<marid_server>:<marid_port>/alert/action

and If maridKey configuration is set in configuration file, Webhook URL should be:

https://<marid_server>:<marid_port>/alert/action?maridKey=changeme

For the parameters that are passed to the alert action script, you can see this document.