Template variables for legacy alerts

Updated at:

This topic describes the template variables that legacy alerts support and how to reference them.

Reference Principles

When you configure a notification method, you can reference template variables in the Content and Subject fields using the ${fieldName} syntax. When Simple Log Service sends an alert notification, it replaces these variables with their actual values. For example, Simple Log Service replaces ${Project} with the name of the project to which the alert rule belongs.
Important The variable name must be an exact match. If a referenced variable does not exist or is invalid, it is rendered as an empty string. If the value of a referenced variable is an object, the value is converted to a JSON string.

Available variables and references

VariableDescriptionExample of Message Content and Alert Subject ConfigurationAlert notification example
AliuidThe ID of the Alibaba Cloud account to which the project belongs.An alert rule was triggered for user ${Aliuid}.An alert rule was triggered for user 117914634953****.
ProjectThe project to which the alert rule belongs.An alert rule in the ${Project} project was triggered.An alert rule in the my-project project was triggered.
AlertIDThe ID of the alert.The alert ID is ${AlertID}.The alert ID is 0fdd88063a611aa114938f9371daeeb6-1671a52****.
AlertNameThe name of the alert rule. The name is unique within a project.The ${AlertName} alert rule was triggered.The alert-1542111415-153472 alert rule was triggered.
AlertDisplayNameThe display name of the alert rule.The ${AlertDisplayName} alert was triggered.The website monitoring alert was triggered.
ConditionThe conditional expression that triggers the alert. In the alert notification, the variable is replaced with the actual value and enclosed in brackets ([]).The conditional expression is ${Condition}.The conditional expression is [5] > 1.
RawConditionThe original conditional expression that triggers the alert.The original conditional expression is ${RawCondition}.The original conditional expression is count > 1.
DashboardThe name of the dashboard associated with the alert.The associated dashboard is ${Dashboard}.The associated dashboard is mydashboard.
DashboardUrlThe URL of the dashboard associated with the alert.The URL of the associated dashboard is ${DashboardUrl}.The URL of the associated dashboard is https://sls.console.aliyun.com/next/project/myproject/dashboard/mydashboard.
FireTimeThe time when the alert was triggered.The alert was triggered at ${FireTime}.The alert was triggered at 2021-01-02 15:04:05.
FullResultUrlThe URL to query the alert history.Click ${FullResultUrl} to view alert details.Click https://sls.console.aliyun.com/next/project/my-project/logsearch/internal-alert-history?endTime=1544083998&queryString=AlertID%3A9155ea1ec10167985519fccede4d5fc7-1678293caad&queryTimeType=99&startTime=1544083968 to view alert details.
ResultsThe parameters and results of the query and analysis. This variable is an array. The following code provides an example:
Note Results variable can contain up to 100 pieces of alert information.
[
  {
    "EndTime": "2021-05-21 18:33:12",
    "EndTimeTs": "1621593192",
    "FireResult": {
      "source": "",
      "time": "1621592292",
      "cnt": "2",
      "status": "403"
    },
    "FireResultAsKv": "[cnt:2,status:403]",
    "LogStore": "nginx-access-log",
    "Query": "status >= 400 | select status, count(*) as cnt group by status",
    "QueryUrl": "",
    "RawResultCount": 2,
    "RawResults": [
      {
        "__source__": "",
        "__time__": "1621592292",
        "cnt": "2",
        "status": "403"
      },
      {
        "__source__": "",
        "__time__": "1621592292",
        "cnt": "1",
        "status": "401"
      }
    ],
    "RawResultsAsKv": "[cnt:2,status:403] \n\n [cnt:1,status:401]",
    "StartTime": "2021-05-21 18:18:12",
    "StartTimeTs": "1621592292",
    "Truncated": false
  }
]

For more information, see Alert log fields.

The start time of the first query and analysis is ${Results[0].StartTime}, and the end time is ${Results[0].EndTime}.
Note In this example, 0 is the chart ID. For more information about how to obtain the chart ID, see View chart IDs.
The start time of the first query and analysis is 2021-05-21 18:18:12, and the end time is 2021-05-21 18:33:12.