Alarm notification content contains special characters, how to deal with it?
When the alarm notification content contains special characters that cause the alarm notification to fail, you can add a filter to the variable of the alarm notification content {{variable | escapejs}} . The logging service converts the specified string or special characters in the specified variable to a Unicode-encoded string based on this configuration. Please refer to the detailed description Filter. explain
When Feishu, DingTalk, or WeCom receive an alert notification, they re-convert the Unicode-encoded string to a special character.
For example, if you set the following notification content containing special characters in the alert policy and reference that content in the content template (the corresponding variable name is {{NotifyMsg}} ), you can use the following variables and filters to Unicode transcode the special characters.
- Notification content in the alert policy
- Variable configuration in content templates
How to avoid special characters in alarm notification content being escaped?
When the log service sends an alarm, it automatically replaces the content variable with the corresponding actual value. If the actual value contains special characters such as quotation marks ("), it will be escaped in some scenarios such as using toJson and toPrettyJson functions, making the notification content less readable. To address this issue, you can add a filter {{variable | safe}} to the corresponding variable to force the content not to be escaped. Please refer to the detailed description Filter. For example {{FireResults}} the actual value of the variable is [{"cnt": 1, "cnt_1": 0}] , and when you use {{toJson (FireResults) }} , the notification will be escaped as [{& quote; cnt & quote;: 1, & quote; cnt_1 & quote;: 0}] . To avoid the notification content being escaped, get the notification content [{"cnt": 1, "cnt_1": 0}] , you can use {{toJson (FireResults) | safe}} .
How to avoid the content of the alarm notification being truncated?
Each alarm notification channel has a notification content length limit. When the length of the notification content after the content is rendered exceeds the limit, the part exceeding the limit will be truncated. For notice content length limit, see Create content template. You can use a for loop statement to iterate over arrays and objects to avoid truncating the notification content. Examples are as follows:
How do I reference the content that triggered the alarm in the alert notification?
You can add a variable {{FireResults}} or {{Results}} to the alert content template to reference the details that triggered the alert in the alert notification. For a detailed description of alarm variables, see Content variable. Examples are as follows: -
- {{FireResults}} Variable Example
-
- {{Results}} Variable Example
-
How to format the notification content, data operations and other operations?
Log service provides rich Content syntax and Content functions for handling alarm notification content. You can format and customize data, text, variables, and other content through content functions and content syntax.