Overview
Ops Manager supports webhook templating using FreeMarker template syntax. You can customize both the HTTP headers and request body content sent to your webhook endpoint. Both templates must produce valid JSON output.
Template Variables
You can use a variety of variables in both the headers and body templates. For more details, check the Alert Model documentation, click the post test message button (random data) or save an aler and inspect the webhook payload (variable names match the JSON keys).
Note
Not all variables are included in every webhook call. Available fields depend on the alert type and status. Make sure your templates handle null values to avoid rendering errors.
The following variables are available in webhook templates:
Variable | Description |
|---|---|
| Timestamp in ISO 8601 date and time format in UTC until which the alert has been acknowledged. |
| Comment left by the user who acknowledged the alert. |
| Username of the user who acknowledged the alert. |
| Unique identifier for the alert configuration that triggered this alert. |
| Unique identifier for the cluster to which this alert applies. |
| Name of the cluster to which this alert applies. |
| Timestamp in ISO 8601 date and time format in UTC when the alert was opened. |
| (Object) Current value of the metric that triggered the alert. |
| Value of the metric. |
| Units for the value. Value depends on the type of metric. |
| The action or state change for this alert notification (Default |
| Name of the event that triggered the alert. |
| Unique identifier of the group (project) for which this alert was opened. |
| Unique identifier for the host to which the metric pertains. |
| Hostname and port of each host to which the alert applies. This can be a hostname, an FQDN, an IPv4 address, or an IPv6 address. |
| Human readable description of the alert. |
| Unique identifier for the alert. |
| Timestamp in ISO 8601 date and time format in UTC when the last notification was sent for this alert. |
| (Array of Object) One or more links to sub-resources and/or related resources. |
| Describes the relationship type of the linked resource (e.g., |
| Link to the resource. |
| Name of the measurement whose value went outside the threshold. |
| Unique identifier of the organization for which this alert was opened. |
| Name of the organization for which this alert was opened. |
| Name of the project (group) for which this alert was opened. |
| Name of the replica set. |
| Unique identifier for the request. (Default |
| Timestamp in ISO 8601 date and time format in UTC when the alert was closed. |
| Request signature, only available in the headers template. (Default |
| Current state of the alert ( |
| Type of host being backed up when |
| Identifying labels set for this alert. |
| Timestamp in ISO 8601 date and time format in UTC when the alert was last updated. |
Regex Helper
Additionally, there is a custom helper available, the re helper, that lets you
use regular expressions to extract data from text within your templates.
re.group(input, regex, group)Returns the specified capture group from the first match. If no match, returns an empty string.
Example:
${re.group("abc-123", "([a-z]+)-(\\d+)", 2)}→123re.findAllGroup(input, regex, group)Returns a list of all group matches.
Example:
<#list re.findAllGroup("error1:12;error2:98;error3:33", "error\\d+:(\\d+)", 1) as val>${val} </#list> Outputs:
12 98 33
Note
The group index is 1-based. If no matches are found, returns an empty string or empty list.
Template Examples
Custom Headers Template
{ "X-Static": "static-value", "X-Secret": "${signature}", "X-Request-Id": "${requestId}", "X-Event": "${event}", "X-Org-Name": "${orgName!''}", "X-Test-Regex-Helper": "${re.group(\"abc-123\", \"([a-z]+)-(\\d+)\", 2)}" }
Custom Body Template
{ "staticValue": "This value is static", "testRegexHelper": [ <#list re.findAllGroup("error1:12;error2:98;error3:33", "error\\d+:(\\d+)", 1) as val> "${val}"<#if val_has_next>,</#if></#list> ], "replicaSetName": "${replicaSetName!''}", "metricName": "${metricName!''}", "orgName": "${orgName!''}", "created": "${created!''}", "groupId": "${groupId!''}", "hostId": "${hostId!''}", "hostnameAndPort": "${hostnameAndPort!''}", "humanReadable": "${humanReadable?js_string}", "orgId": "${orgId!''}", "alertConfigId": "${alertConfigId!''}", "eventTypeName": "${eventTypeName!''}", "links": [ <#list links![] as link> { "rel": "${link.rel!''}", "href": "${link.href!''}" }<#if link_has_next>,</#if> </#list> ], "id": "${id!''}", "projectName": "${projectName!''}", "updated": "${updated!''}", "currentValue": { "number": ${(currentValue.number)!0}, "units": "${(currentValue.units)!''}" }, "status": "${status!''}" }
Testing Webhook Templates
After configuring your webhook templates, you can test them using the Test Alert button in the alert configuration interface. This sends a test notification with sample data to verify your template renders correctly.