Built-in functions for content templates allow you to manipulate data and enrich the format and style of your notifications. This topic describes the syntax and examples of these built-in functions.
General functions
Math functions
|
Function |
Description |
Filter |
Example |
|
float(value, default=0.0) |
Converts an integer or a string to a floating-point number. If the conversion fails, the function returns 0.0 by default. Use the default parameter to specify a different return value for a failed conversion. |
Supported |
|
|
int(value, default=0) |
Converts a string or a number to an integer. If the conversion fails, the function returns 0 by default. Use the default parameter to specify a different return value for a failed conversion. |
Support |
|
|
length(value) |
Returns the length or number of items in an object, such as a string, list, or tuple. |
Supported |
|
|
abs(value) |
Returns the absolute value of a number. |
Support |
The result of |
|
min(value) |
Returns the minimum value. |
Support |
The result of |
|
max(value) |
Returns the maximum value. |
Supported |
The result of |
|
ceil(value) |
Rounds a number up to the nearest integer. |
Support |
The result of |
|
floor(value) |
Rounds a number down to the nearest integer. |
Supported |
The result of |
|
round(value, 1) |
Rounds a number to the nearest integer. The argument specifies the number of decimal places to retain. For example, |
Support |
|
|
sum(value) |
Calculates the sum. |
Supported |
The result of |
String functions
|
Function |
Description |
Filter |
Example |
|
string(value) |
Converts an object to a string. |
Support |
The result of In this case, 1.23 is a string. |
|
capitalize(value) |
Converts the first character of a string to uppercase and all other characters to lowercase. |
Support |
The result of |
|
lower(value) |
Converts a string to lowercase. |
Support |
The result of |
|
upper(value) |
Converts a string to uppercase. |
Support |
The result of |
|
title(value) |
Returns a title-cased version of the string, where the first character of each word is uppercase and the rest are lowercase. |
Support |
The result of |
|
trim(value) |
Removes whitespace from the beginning and end of a string. |
Supported |
The result of |
|
replace(value, old, new) |
Replaces a substring within a string. |
Not supported |
The result of |
|
wordcount(value) |
Counts the number of words in a string. |
Support |
The result of |
|
truncate(value, n, end='') |
Truncates a string.
|
Not supported |
|
|
quote(value) |
Encloses a string in double quotation marks (""). |
Support |
|
|
indent(value, n=4) |
Indents each line of a string. The default indent is 4 spaces. Use the n parameter to specify the number of spaces for the indent. |
Supported |
|
|
startswith(value, prefix) |
Checks if a string starts with a specific prefix. |
Support |
The result of |
|
endswith(value, suffix) |
Checks if a string ends with a specific suffix. |
Support |
The result of |
|
removeprefix(value, prefix) |
Removes the prefix from a string. |
Support |
The result of |
|
removesuffix(value, suffix) |
Removes the suffix from a string. |
Supported |
The result of |
|
split(value, sep=None, maxsplit=-1) |
Splits a string.
|
Support |
|
List and object functions
|
Function |
Description |
Filter |
Example |
|
enumerate(value) |
Pairs each element in an iterable with its index, returning a list of (index, element) tuples. |
Not supported |
The result of |
|
list(value) |
Converts an iterable object to a list. |
Supported |
|
|
dict(value) |
Creates a dictionary, similar to using |
Not supported |
The result of |
|
first(value) |
Returns the first item in a list. |
Support |
The result of |
|
last(value) |
Returns the last item in a list. |
Supported |
The result of |
|
sort(value, reverse=true) |
Sorts the elements of a list. To sort in reverse order, specify reverse=true. |
Help and support |
|
|
dictsort(value) |
Sorts the key-value pairs of an object by key and returns an array of the sorted pairs. |
Support |
|
|
join(value, d='') |
Joins the elements of a list with a separator. Use the d parameter to specify the separator. |
Support |
|
Formatting functions
|
Function |
Description |
Filter |
Example |
|
escape_markdown(value) |
Escapes special Markdown characters. |
Support |
The result of |
|
escape_html(value) |
Escapes special HTML characters. |
Support |
The result of |
|
to_json(value) |
Converts an object to JSON format. |
Support |
|
|
parse_json(value) |
Parses a string into a JSON data structure. |
Support |
|
Encoding and decoding functions
|
Function |
Description |
Filter |
Example |
|
base64_encoding(value) |
Encodes the input value in Base64. |
Supported |
The result of |
|
base64_decoding(value) |
Decodes the Base64-encoded input value. |
Support |
The result of |
|
md5_encoding(value) |
Generates the MD5 hash of the input value. |
Support |
The result of |
|
url_encoding(value) |
URL-encodes the input value. |
Support |
The result of |
|
url_decoding(value) |
URL-decodes the input value. |
Support |
The result of |
Date and time functions
|
Function |
Description |
Filter |
Example |
|
parse_date(value, fmt="%Y-%m-%d %H:%M:%S") |
Converts a Unix timestamp or formatted string to a datetime object. Use the fmt parameter to specify the datetime format. |
Support |
|
|
format_date(value, tz=None, fmt="%Y-%m-%d %H:%M:%S") |
Formats a datetime value as a string. Use the fmt parameter to specify the output format. If the input value is not a date object, the function first converts it to a date object and then formats it. For more information about datetime format directives, see Datetime formatting instructions. For more information about time zones, see Time zones. |
Not supported |
|
|
timestamp(value) |
Converts a date and time string to a Unix timestamp. If the input value is not a date object, the function first converts it to a date object before returning the timestamp. |
Supported |
|
|
format_duration(value, locale='en-US', sep='') |
Formats a time interval. The unit of value is seconds. Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
Alerting functions
Alerting functions operate within the alert context and adapt to the content template configuration. They automatically detect the following:
Running alerting functions in different alert contexts may return different results.
-
Alert properties, such as the severity and status of the current alert.
-
The language configured in the content template, such as Chinese or English.
-
The notification channel, such as DingTalk or email.
|
Function |
Description |
Filter |
Example |
|
format_type(alert.type, locale=None) |
Converts the alert type to a text description. Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
|
format_region(alert.region, locale=None) |
Converts the alert region to a text description. Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
|
format_severity(alert.severity, locale=None) |
Converts the alert severity to a text description with colored formatting. Note
Colored text is supported only in DingTalk, WeCom, email, and Message Center notifications. Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
|
format_status(alert.status, locale=None) |
Converts the alert status to a text description with colored formatting. Note
Colored text is supported only in DingTalk, WeCom, email, and Message Center notifications. For other channels, the output remains unchanged. Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
|
to_list(value) |
Converts an array or object to a list. |
Support |
|
|
annotations_to_list(alert.annotations, locale=None) |
Converts alert annotations to a list. This function works like to_list(alert.annotations), but automatically maps standard field names to human-readable labels. For example, it converts the title field to Use the locale parameter to specify the language. For valid values of the locale parameter, see Valid values for the locale parameter in alerting functions. |
Support |
|
|
blockquote(value) |
Adds blockquote formatting to the notification content.
|
Supported |
|
References
-
Valid values for the locale parameter in alerting functions
locale value
Description
None or an empty string
Uses the language configured in the content template.
en-US
English.
zh-CN
Chinese.
-
Alert annotation field mappings
Annotation
Mapping value (Chinese)
Mapping value (English)
title
Title
Title
desc
Description
Description
anomaly_score
Anomaly Score
Anomaly Score
job_id
Task ID
Task ID
model_id
Model ID
Model ID
severity
Anomaly Severity
Anomaly Severity
__pub_alert_app__
Application
Application
__pub_alert_protocol__
Protocol
Protocol
__pub_alert_region__
Region
Region
__pub_alert_service__
Service
Service
__ensure_url__
Anomaly Confirmation
Anomaly Confirmation
__mismatch_url__
False Positive Confirmation
False Positive Confirmation
__plot_image__
Time Series Chart
Time Series Chart
__host_ip__
Machine Address
Machine Address
__host_group_name__
Machine Group Name
Machine Group Name
__cloud_monitor_type__
CloudMonitor
CloudMonitor