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:
Data type
The content variable syntax is similar to Python and supports the following data types.
Separator
Separators are used to distinguish different types of objects. Supported separators in TLS alarm notification include:
Operator
The following operators are supported in TLS alarm notifications. Arithmetic and comparison operators usually work only with variables or constants of numeric types.
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:
Iteration
In alarm notifications, TLS supports iteration over arrays and objects using the for loop statement. The supported iteration methods are as follows:
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 %}.
After escaping and formatting, the output result is as follows:
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.
Variable definition
- Use the with statement to define variables. Syntax format:
- Define variables using set keyword. Syntax format: