• Log in

Notification message templates

Notification message templates enable you to customize your notification event data before it's sent to your third-party destination. The templates map your custom values to the values used by your third-party destination.

This gives you full control over what data will be sent and where, as well as being able to fully engage with the services you use.

Message template variables

A message template is what you use to convert New Relic event data to data that's consumable by your third-party service. Variables are specific attributes that are mapped to data fields in your third-party service.

Message templates are written in a simple templating language called Handlebars. Variables in the message templates are written as expressions inside double curly braces {{ }}.

Use the notification message template to map your New Relic notifications to the fields in your external services.

The variables menu

The New Relic variable names are listed in the message template variables menu. The variables are grouped into subcategories.

In the variables menu, type {{ to select from a list of variables. As you type, variable names appear via autocomplete. The variable type is written on the right-hand side. You can add enriched data to these variables.

The variables menu shows the options you have when mapping New Relic notification fields onto the fields in your external service.

Use the Handlebars syntax

When an event generates a notification, the message template uses the Handlebar variables to map the notification data to the fields used by your third-party service.

The Handlebars language provides many features in addition to basic variable replacement, including evaluating nested input objects and functions, such as iterations (loops), conditional statements, and more. In Handlebars, these functions are called helpers.

Helper functions

Our message templates support the Handlebars built-in helpers.

In addition, we've added other helpers that might be useful to you.

Usage examples

The examples are based on a variable called data:

"data": {
"tags":["infra, team-a"],
"name": "Alice",

The data value has an equivalent, dot-notated format:

"data.tags": ["infra, team-a"]
"data.id": 123456789
"data.name": "Alice"

Validate data

If id equals 123456789, then the output is valid. If not, the output is not valid.

{{eq data.name "Alice" yes='valid' no='not valid'}}

If name equals Alice, then the output is valid.

Return JSON

Get the tags and object’s properties in a JSON form:

{{json data.tags}}

This would return the following JSON:

["infra", "team-a"]

Get values from an array

Get the first tag from the tags array:

{{json data.tags.[0]}}

This would return the first value from the array:


Iterate through an array

Iterate a variable of type array and aggregate the values into a string:

{{#each tags}}{{this}}{{#unless @last}}, {{/unless}}{{/each}}

The result contains the tags, seperated by commas (the trailing comma is omitted):

infra, team

Similarly, iterate the data variable, aggregate the object’s values, and output a JSON element:

{{#each (json data)}}{{this}}{{/each}}

This would return a JSON such as:

"tags": ["infra, team-a"],
"name": "Alice",
"id": "123456789"

Iterate the data variable, then aggregate the object’s entries to a string:

{{#each data}}{{@key}}: {{this}}{{#unless @last}}, {{/unless}}{{/each}}

This would return a string such as:

tags: infra,team-a, name: Alice, id: 123456789

Handle missing attributes

In some cases, an attribute may be missing from the variables menu, or not exist whatsoever.

We can use the #if statement to set a fallback, such as:

{{#if data.type}} {{ json data.type }} {{else}}"N/A"{{/if}}

would return the string "N/A".

Copyright © 2022 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.