You need to enable JavaScript to run this app.
Observability Platform

Observability Platform

Copy page
Download PDF
Notification templates
Notification template syntax
Copy page
Download PDF
Notification template syntax
When a matched rule in a notification policy or event is triggered, a notification message is sent via email, Feishu, DingTalk, phone, Webhook, and other methods based on the content defined in the notification template. The system provides a preset notification title and content for each notification type by default. If the preset templates do not meet your requirements, you can customize a notification template based on your actual scenario. This topic describes the syntax supported for writing notification templates.​
Background​
The notification title and content in a notification template are written and rendered using Markdown and Go Template syntax. Before configuring a custom notification template, you need to first understand basic Go Template syntax.​
tip​
The template writing syntax is universal, but the supported extension functions and variables vary by notification type. For more information, see:​
Common Go template syntax​
Character .​
The . character is used to render the specified object within the current scope.​
Example 1: Obtain all contents within the top-level scope, which are all contents in an alerting notification.​
​
{{ . }}​
​
Expected response result: The output contains all content in the alert notification.​
Example 2: Query the Region field of the alert policy.​
​
{{ .Region }}​
​
The following sample code shows the expected response result:​
​
cn-beijing​
​
Variable​
Variables are used to store input data, and after data is passed into variables, the entire template can access the data by using the variables. For example, in {{$rulename := .RuleName}}, use $rulename as a variable to store the alert policy name, and then use {{$rulename}} to access the variable.​
Example: Store the alert policy name in $rulename and then output $rulename.​
​
{{ $rulename := .RuleName }} {{$rulename}}​
​
The following sample code shows the expected response result:​
​
This is a alarm strategy demo​
​
Conditional statement​
The conditional statement if/else uses if to check the data. If the condition is not met, the content of else is executed. The if statement returns false when the evaluation condition is a null value, 0, nil, an empty string, or a zero-length string.​
Example: If the value of .Level in the alert information equals warning, the output is Warning.​
​
{{if eq "warning" .Level }} Warning alarm {{ end }}​
​
The following sample code shows the expected response result:​
​
Warning alarm​
​
Comparison function​
The comparison function is used to compare the data size. It is often used together with if/else statements to determine the execution of statements. The following table shows commonly used comparison functions.​
​
Function name​
Description​
eq​
Equal to​
ne​
Not equal to​
lt​
Less than​
le​
Less than or equal to​
gt​
Greater than​
ge​
Greater than or equal to​
​
Example: If the value of .Level is equal to warning, the output is Warning.​
​
{{if eq "warning" .Level }} Warning alarm {{ end }}​
​
The following sample code shows the expected response result:​
​
Warning alarm​
​
Logical function​
Logical functions primarily include and, or, and not, which are used to perform logical negation, conjunction, and disjunction across multiple conditions.​
Example: If the value of Region is cn-beijing and the value of Level is warning, the output is Warning level alert from Beijing.​
​
{{if eq "cn-beijing" .Region and eq "warning" .Level }} Beijing Warning Alarm {{ end }}​
​
The following sample code shows the response result:​
​
Beijing Warning Alarm​
​
Common built-in functions​
The following table describes the common Go template built-in functions.​
​
Function name​
Description​
Example​
len​
Obtains the length of an array.​
Obtain the length of the Alerts array.​
​
{{ len .Region }}​
​
The following section shows the expected response result:​
​
10​
​
​
​
Last updated: 2026.09.07 19:40:07