Notification template syntax
The notification templates use the Go templates syntax. You can use this syntax to dynamically fill notifications with content: load data from the fields of the corresponding objects, insert links, or convert dates to a different format. You can use the template syntax in the subject as well as the body of the message. This article briefly describes the syntax and lists the fields that can be used for certain types of events, and additional functions that can be applied to these fields. You can read more about the syntax in the official Go language documentation.
In the template, you can reference the object fields depending on the selected type of event. The fields of the corresponding objects can contain simple values such as a string or a number:
|
The message will display the alert name, which is the contents of the CorrelationRuleName
field of the alert data model.
Some fields may contain data arrays, for example, alert fields with related events, assets, and accounts. Such nested objects can be queried by using the range
function, which sequentially queries the fields of the first 50 nested objects. When using the range
function to query a field that does not contain a data array, an error is returned. Example:
|
The message will display the values of the DeviceHostName
and CreatedAt
fields from 50 assets related to the alert:
|
You can use the limit
function to limit the number of objects returned by the range
function:
|
The message will display the values of the DisplayName
and CreatedAt
fields from 5 assets related to the alert, with the words "Devices" and "Creation date" marked with the <strong>
HTML tag:
|
Nested objects can have their own nested objects. They can be queried by using nested range
functions:
|
The message will show ten service IDs (ServiceID
field) from the base events related to five correlation events of the alert (50 lines in total). Please note that events are queried through the nested EventWrapper
structure, which is located in the Events
field in the alert. Events are available in the Event
field of this structure, which is reflected in the example above. Therefore, if field A
contains nested structure [B]
and structure [B]
contains field C
, which is a string or a number, to query field C
, you must specify the path {{ A.C }}
.
Some object fields contain nested dictionaries in key-value format (for example, the Extra
event field). They can be queried by using the range
function with the variables passed to it: range $placeholder1, $placeholder2 := .FieldName
. The values of variables can then be called by specifying their names. Example:
|
The message will use an HTML tag<br> to show key-value pairs from the Extra
fields of the base events belonging to the correlation events. Data is called from five base events out of each of the three correlation events.
You can use HTML tags in notification templates to create more complex structures. Example table for correlation event fields:
|
Use the link_alert function to insert an HTML alert link into the notification email:
|
A link to the alert window will be displayed in the message.
Templates also support more complex constructs such as local variable declaration, comparison operators, and control structures. Below is an example of how you can extract the data on max asset category from the alert data and place it in the notifications:
|
Object fields supported in templates
The following table lists the fields that can be accessed from templates, depending on the type of event.
Supported object fields
Type |
Available fields |
Alert created
|
All fields of the alert data model are supported, including nested arrays and structs. |
Report generated |
Example of adding links to a report notification template: You can |
Task finished |
|
Sources monitoring alert |
|
KASAP group changed |
|
Functions in notification templates
Functions available in templates are listed in the table below.
Functions in templates
Function |
Description |
---|---|
|
Takes the time in milliseconds (unix time) as the first parameter; the second parameter can be used to pass the time in RFC standard format. The time zone cannot be changed. Example call: Call result: 18 Nov 2022 13:46 Examples of date formats supported by the function:
|
|
Lets you iterate over arrays or sets of key-value pairs, sequentially referring to the fields of the first 50 items. |
|
This function is called inside the Example call:
|
|
Generates a link to the alert with the URL specified in the SMTP server connection settings as the KUMA Core server alias or with the real URL of the KUMA Core service if no alias is defined. Example call:
|
|
Generates a link to the task in KUMA. Example call:
|
|
Takes the form of a link that can be followed. Example call:
|