• Get started
  • Documentation

Dynamic fields in Opsgenie integrations

Opsgenie parses your data to construct rich and informative alerts. You can use dynamic fields to customize alert properties, as well as alert conditions.

Draggable Fields

Draggable fields bring significant data for creating and managing well-informed alerts. Opsgenie Integrations Framework provides different dynamic fields for every integration, specific to the integrated tool. Dynamic fields can be used in Filters of your integration actions as well as Alert Fields. In Filter, fields are available to choose in the condition drop lists. In Alert Fields, you can just drag a dynamic field into any input you find appropriate.

An image showing a draggable field in an integration setting.

The expressions with double-curly braces are interpreted by Opsgenie as dynamic fields; and populated with dynamic data at every notification that's sent to Opsgenie. For example, let's say someone created an issue in JIRA; and entered "This is the summary" as summary. Using Opsgenie's JIRA integration, "[Jira] {{summary}}" for Message in a Create Alert Action will yield an alert with the message "[Jira] This is the summary" and notify the users. All we needed to do was drag {{summary}} to Message; and when the issue was created Opsgenie automatically got notified and created an alert with the issue's summary in the message for us.

You can mix static text with dynamic fields. As you can see in the example above, the "[Jira] " in "[Jira] {{summary}}" is static and will be at the beginning of every created alert's message. "{{summary}}" can be different for each alert.

Using Raw Parameters From Webhook Url, Payload and Headers

You can also inject url parameters or http payload parameters from webhooks directly into your alerts. Let's clarify with an example:

Suppose you're using Opsgenie Jira integration. Jira sends to Opsgenie a variable named timestamp in the webhook payload; but timestamp hasn't been made available as a draggable field in the Integrations page. If you still need to use timestamp in your alerts, you can:

  • Go to Advanced Settings of your integration

  • Add {{_payload.timestamp}} to wherever you need on the input fields.

  • Save the integration.

Nested payload variables are accessible as well. In the Jira example, we could also use _payload.issue.fields.environment to access the following value that is in the http body of the webhook:

Text

1 2 3 4 5 6 7 { "issue" : { "fields" : { "environment" : "env_val" } } }

Url query parameters of a webhook are also accessible via {{_url.param}} where param is the parameter key. You can add custom parameters to the webhook url and inject it into your alerts. To clarify this with an example:

 

Suppose you're using Opsgenie Stackdriver integration. You're monitoring multiple projects and want to use a single integration for all your alerts, but still want to have a way of distinguishing which alert belongs to which domain. One thing you can do is to use a custom parameter for each of your project.

You can add your custom parameter to the webhook url of the Stackdriver integration, like param1=val1, and insert {{_url.param1}} in the integration config to access it.

Note that accessing request url, payload and headers parameters is not available for actions via Alert API

Headers of a webhook request is also available via {{_headers.param}} where param is the name of the header. You can use all the headers of a request in your alert fields.

You can use headers of an email via {{_headers.PARAM1}} notation for the email based integrations. For example, you can use {{_headers.IMPORTANCE}} in the alert fields for an email based integration. Note that you should use UPPER CASE letters for the keys.

You can also use string processing methods on dynamic fields to further manipulate and control your alert fields. For example, your Opsgenie JIRA Integration has an Add Note Action, and Note is configured as "note: {{comment_body.substringAfter("is")}}". Now when someone in JIRA comments on an issue with "This is the comment", the Opsgenie alert that's associated with the issue will be added a note, with the text "note: the comment".

The complete list of methods you can use in dynamic fields are listed below:

substring(int from), substring(int from, int to): yields the string between specified indices. from is included to is excluded

{{from_name.substring(5,20)}}

substringAfter(String from): yields the string between specified indices. from is included to is excluded

{{subject.substringAfter("Host")}}

substringBefore(String to): yields the string before the specified parameter

{{from_address.substringBefore("@")}}

substringBetween(String from, String to): yields the string between from and to parameters

{{subject.substringBetween("URL:","(")}}

extract(regular expression): yields part of the string that matches the parenthesized section of the regular expression.

{{message.extract(/Host: (\S+)/)}}

toDate(String format) converts millisecond-based timestamp into date format, following Java formatting . The default format is "yyyy-MM-dd HH:mm:ss ZZZ".

{{create_timestamp.toDate()}}

get(int index) yields the element at the given index of an array.
{{myArray.get(0)}}

Still need help?

The Atlassian Community is here for you.