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.

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
Setting Description Mandatory Default Value
maridKey Marid 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.
No changeme
HTTP Web Server Configuration Settings
Setting Description Mandatory Default Value
http.server.enabled Enable/disable HTTP web server Yes false
http.server.host Http web server host No 127.0.0.1
http.server.port Http web server port No 8080
http.server.maxContentLength Maximum HTTP request content length for each request. Requests with higher content length will be discarded by the web server. (in bytes) No 2000000
http.server.threadpool.size The maximum number of simultaneous HTTP connection No 100
HTTPS Web Server Configuration Settings
Setting Description Mandatory Default Value
https.server.enabled Enable/disable HTTPS web server Yes false
https.server.host Https web server host No 8443
https.server.port Https web server port No 127.0.0.1
https.server.maxContentLength Maximum HTTPS request content length for each request. Requests with higher content length will be discarded by the web server. (in bytes) No 2000000
https.server.keystore HTTPS server keystore file path No <MARID_HOME>/conf/.keystore
https.server.keyPassword HTTPS server keystore file password No 123456
https.server.threadpool.size The maximum number of simultaneous HTTP connection No 100
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:

Parameter Description
params The map variable to access parameters passed by HTTP/S requests.
request HTTP request object. HTTP request content, headers, method, remoteAddress can be accessed via this parameter.
response HTTP response which will be returned. Response content, contentType and status code may be modified via this parameter.
conf A reference to configuration file properties. Every configuration property is accessible via this parameter.
logger Logging utility. All script logs will be written to script.log file in LOGS_DIR directory.
opsgenie The 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 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.

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.