You need to enable JavaScript to run this app.
Torch Log Service

Torch Log Service

Copy page
Download PDF
Alarm notification content template
Content syntax
Copy page
Download PDF
Content syntax
TLS offers diverse content syntax for alarm notifications, such as special character escaping and variable condition checking. With this feature, you can customize notification content and display style in advanced scenarios to make notifications diverse and clearer.​
Features overview​
TLS provides built-in content syntax for alarm features, supporting custom design of notification content and style to meet the requirements for notification customization in various scenarios. When designing alarm notification content, follow the content syntax described in this document for an enhanced user experience.​
The syntax provided by TLS includes the following:​
​
Type​
Syntax​
Description​
Basic grammar support​
Supports data types including integers, floating-point numbers, strings, arrays, and dictionaries.​
​
The separator is used to distinguish different types of objects.​
​
Supports arithmetic and other operators.​
Actions​
Remove the whitespace at the specified position.​
​
Conditionally evaluate parameters or logical comparison expressions.​
​
Iterate over arrays and objects using a for loop statement.​
​
Use the verbatim tag to escape special statements.​
​
Insert comment information into notification content using comment syntax.​
​
Define variables using the with statement.​
​
Data type​
The content variable syntax is similar to Python and supports the following data types.​
​
Data type​
Description​
Number​
Includes integers (Integer) and floating-point numbers (Double), such as 1, 3.1, and -2.​
String​
All strings must be enclosed in double quotation marks ("") or single quotation marks (''). Special characters in strings need to be escaped. The supported escape character is the backslash (\). For example, ""source"" should be written as "\"source\"".​
Boolean value​
Booleans are supported, including True and False.​
Null value​
None.​
List​
Supports list type. The term "list" varies across programming languages. It may be called array, list, slice and other terms in other programming languages. For example, list("abc", "xyz").​
Dictionary​
Supports dictionary type. Different programming languages use terms like object or dictionary. For example, dict("abc", "xyz").​
​
Separator​
Separators are used to distinguish different types of objects. Supported separators in TLS alarm notification include:​
​
Separator​
Use cases​
Example value​
{{ }}​
Used for variables or expressions; is the standard format for both.​
  • Variable: {{AccountID}}​
  • Expression: {{ 1 \+ 2 }}​
  • Number: {{ 123 }}​
  • String: {{ "abc" }} or {{ 'xyz' }}—double quotation marks ("") or single quotation marks ('') must be used.​
  • Function call: {{list(a,b,c,d)}}​
{% %}​
Used to control statements.​
​
{% if count >0 %}​
Error exists.​
{% else %}​
No error.​
{% endif %}​
​
{# #}​
Used to insert comments in the notification content. Comments only appear in the alarm policy configuration and are not sent to recipients with the notification.​
​
{# This is one single-line comment #}​
​
{% comment %}​
This is the first line in a multi-line comment.​
This is the second line in a multi-line comment.​
{% endcomment %}​
​
​
Operator​
The following operators are supported in TLS alarm notifications. Arithmetic and comparison operators usually work only with variables or constants of numeric types.​
​
Category​
Operator​
Description​
Arithmetic operation​
+​
Addition​
​
-​
Subtraction​
​
*​
Multiplication​
​
/​
Division, the return value is a floating-point number.​
​
%​
Modulus​
Comparison operations​
==​
Equal to​
​
!=​
Not equal to​
​
>​
Greater than​
​
>=​
Greater than or equal to​
​
<​
Less than​
​
<=​
Less than or equal to​
Logical operation​
&& or and​
And operation​
​
|| or or​
Or operation​
​
! Or not​
Negation​
Other operations​
In​
Used to determine inclusion, returning a Boolean result.​
For example, judge the following types:​
  • Array: {{ 400 in list(401, 402, 403) }}.​
  • Object: {{ "abc" in dict("abc", "xyz") }}.​
  • String: {{ "error" in "errorLog" }}.​
​
()​
Combine operations, such as: {{ x > y and (x > z or y > z) }}.​
​
Remove whitespace characters​
By default, within the content enclosed by separators:​
  • Spaces between separators and other objects are ignored, such as spaces between separators and expressions or separators and variables. For example, {{ AccountID }} is equivalent to {{AccountID}}. In the notification content, this variable is replaced by the actual account ID.​
  • Whitespace outside the separator is preserved, such as spaces, tabs, or line breaks outside the separator. For example, An alarm rule was triggered under the user's {{AccountID}} account with {{Topics}}. The whitespace between two variables will be preserved.​
  • The alarm notification syntax supports removing extra whitespace by using hyphens (-). Add a hyphen at the beginning or end of a separator to remove all consecutive whitespace before or after the separator. For example, {{ abc -}} and {{- xyz }} will be rendered as abc and xyz.​
  • You can also remove whitespace in the following ways:​
  • Remove all consecutive whitespace next to the left of the separator: {{- or {%-​
  • Remove all consecutive whitespace next to the right of the separator: -}} or -%}​
Notice​
  • Whitespace removal only applies to spaces outside the separator. For example, {{ "abc " }} {{- "xyz"}} formats as abc xyz.​
  • No space may be inserted between the hyphen (-) and the separator; otherwise, it will be treated as a normal character. For example, in {{- abc }}, the whitespace removal syntax is valid, and after formatting, it becomes abc; in {{ - abc }}, the whitespace control operation is invalid, and after formatting, it becomes -abc.​
  • By default, blank lines will be deleted. It is not necessary to use this syntax for deletion.​
Conditional judgment​
In notification content, TLS can use specified if statements to conditionally judge parameters or logical comparison expressions, and then dynamically display content based on the results.​
  • Truth value judgment: Passing a regular variable or constant after if means checking its truth value. The following characters will be recognized as false by TLS, while other values are considered true:​
  • Boolean value false, number 0, and empty string ""​
  • Comparison: Enter a logical comparison expression after if to evaluate based on the result. For example, {{ if ConsecutiveAlertNums >= 5 }} is used to check if the number of consecutive alerts is 5 or greater.​
Conditional judgment supports the following forms:​
​
Using method​
Example value​
if​
​
{% if ConsecutiveAlertNums >= 300 %}​
Continue to send alarms.​
{% endif %}​
​
if-else​
​
{% if ConsecutiveAlertNums >= 300 %}​
Continue to send alarms.​
{% else %}​
Send alarms briefly.​
{% endif %}​
​
if-elif​
​
{% if ConsecutiveAlertNums >= 300 %}​
Continue to send alarms.​
{% elif ConsecutiveAlertNums >= 150 %}​
Send alarms briefly.​
{% endif %}​
​
if-elif-else​
​
{% if ConsecutiveAlertNums >= 300 %}​
Continue to send alarms.​
{% elif ConsecutiveAlertNums>=100 && type == 2 %}​
Restore alarm.​
{% else %}​
Send alarms briefly.​
{% endif %}​
​
If nesting​
​
{% if ConsecutiveAlertNums >= 300 %}​
Continue to send alarms.​
{% else %}​
{% if ConsecutiveAlertNums >= 150 && type==1 %}​
Send alarms briefly.​
{% elif type==2 %}​
Restore alarm.​
{% endif %}​
{% endif %}​
​
​
Iteration​
In alarm notifications, TLS supports iteration over arrays and objects using the for loop statement. The supported iteration methods are as follows:​
​
Using method​
Example value​
Array iteration​
​
{% for log in QueryResultStr %}​
{{ log }}​
{% endfor %}​
​
Array iteration with index access​
​
  • Access array elements by index:​
  • ​
    {%-for i in until(Topics|length) -%}​
    {{i}}:{{Topics[i]}}​
    {%endfor-%}​
    ​
  • Loop starting from the specified index:​
  • ​
    {%-for i in untilStep(1,Topics|length,1) -%}​
    {{i}}:{{Topics[i]}}​
    {%endfor-%}​
    ​
Object iteration​
Use a for loop to convert an object into a Key:Value pair format and iterate through it.​
​
{% for key, val in dict("a",1,"b",2) %}​
{{ key }}: {{ val }}​
{% endfor %}​
​
Nested loop​
​
​
{%-for logs in QueryLog%}​
{%- for log in logs%}​
{{log.name}}​
{{log.type}}​
{{log.double_key}}​
{{log.obj_key.key1}}​
{{log.obj_key.key2}}​
{{log.obj_key.key_long}}​
{{log.obj_key.key_double}}​
{%endfor-%}​
{%endfor-%}​
​
​
Special character escaping​
If you need to add {{ or similar special characters in alert notification content, and such characters should not be parsed as separators or variable syntax, you must escape these special characters when configuring the notification content. You need to wrap content that needs to be output in its original style with the verbatim tag.​
For example, the following configuration retains all content between {% verbatim %} and {% endverbatim %}.​
​
{% verbatim %}​
{{ QueryResultStr }}​
{% endverbatim %}​
​
After escaping and formatting, the output result is as follows:​
​
{{ QueryResultStr }}​
​
Content annotation​
You can insert comments into notification content using annotation syntax. Comments only appear in alarm policy configuration and are not sent to recipients with the notification content.​
​
Comment types​
Syntax​
Example value​
Single-line comment​
​
{# #}​
​
​
{# This is a line of comment. #}​
​
Multi-line comment​
​
{% comment %}​
{% endcomment %}​
​
​
{% comment %}​
This is the first line in a multi-line comment.​
This is the second line in a multi-line comment.​
{% endcomment %}​
​
​
Variable definition​
  • Use the with statement to define variables. Syntax format:​
  • ​
    {%with t=list("a","b")%}​
    {%endwith%}​
    ​
  • Define variables using set keyword. Syntax format:​
  • ​
    {% set t=0 %}​
    ​
​
Last updated: 2026.04.14 10:38:09