The alert feature of Log Service allows you to select one or more notification methods, including Email, WebHook-DingTalk Bot, WebHook-Custom, and Notifications.

Notification methods

Email

You can configure Log Service to send alert notifications by email. When an alert is triggered, Log Service sends an email to specified email addresses.

  1. Configure an alert in the Log Service console. For more information, see Configure an alert. Select Email from the Notifications drop-down list.
  2. Enter one or more email addresses in the Recipients field to receive alert notifications, and enter an email subject in the Subject field.
    For example, you can enter Log Service Alert. The email subject must be 1 to 100 characters in length and can contain template variables. For more information, see Template variables.
  3. Enter the email content in the Content field.
    • Separate multiple email addresses with commas (,).
    • You can enter template variables in the Content field.
    • The alert notification that you enter in the Content field must be 1 to 500 characters in length.
    Alert notification by email
  4. Click Submit.

WebHook-DingTalk Bot

You can configure Log Service to send alert notifications by using DingTalk. When an alert is triggered, the DingTalk chatbot sends an alert notification to a specified DingTalk group. You can also specify group members to be reminded by using an at sign (@).
Note Each DingTalk chatbot can send up to 20 alert notifications per minute.
  1. Open DingTalk on your computer and select the target DingTalk group.
  2. In the upper-right corner of the chatbox, click the Group Settings icon, and then choose Group Assistant > Add more.
  3. Select Custom (Custom message services via Webhook), and click Add.
  4. Enter a ChatBot Name and select an option in the Security Settings section.
    Note We recommend that you select Custom Keywords in the Security Settings section. You can enter up to 10 custom keywords. After you set custom keywords, only messages that contain at least one of these keywords can be sent by DingTalk chatbot.
  5. Select "I have read and accepted DingTalk Custom Robot Service Terms of Service", and then click Finished. Click Copy to copy the webhook URL.
  6. Configure an alert in the Log Service console. Select WebHook-DingTalk Bot from the Notifications drop-down list. For more information, see Configure an alert.
  7. In the Request URL field, paste the webhook URL that you copied in Step 5, and then select None, All, or Specified Members in the Recipients section.
    If you select Specified Members, enter their mobile phone numbers in the Tagged List field. Separate multiple mobile phone numbers with commas (,).
  8. Enter the notification content in the Content field.
    The content is generated by default. You can modify the content as needed.
    To remind one or more DingTalk group members by using an at sign (@), you must add mobile phone numbers in the @Mobile phone number format to the Content field. Notification content

WebHook-Custom

You can configure Log Service to send alert notifications to a custom webhook URL. When an alert is triggered, Log Service sends an alert notification to the custom webhook URL by using a specified method.
Note The timeout period of the WebHook-Custom notification method is five seconds. If no response is received within five seconds after a notification request is sent, the notification request fails.
  1. Configure an alert in the Log Service console. For more information, see Configure an alert. Select WebHook-Custom from the Notifications drop-down list.
  2. Enter your custom webhook URL in the Request URL field and select a Request Method.
  3. Optional: Optional. Click Add Request Headers to add request header fields.
    The request header contains the field Content-Type: application/json;charset=utf-8 by default. You can add request header fields as needed.
  4. Enter the notification content in the Request Content field.
    Alert notification by WebHook-Custom

    When an alert is triggered, Log Service sends the specified notification content to the custom webhook URL by using the specified method.

  5. Click Submit.

Notifications (recommended)

In the Alibaba Cloud Message Center console, you can specify the contacts to receive Log Service alert notifications. When an alert is triggered, Log Service sends an alert notification to the contacts by using the method that is specified in the Message Center console.

  1. Configure an alert in the Log Service console. For more information, see Configure an alert. Select Notifications from the Notifications drop-down list.
  2. In the Message Center console, choose Message Settings > Common Settings in the left-side navigation pane.
    Message settings
  3. Find Log Service Alarm Notification in the Notification Type column, and then click Modify in the Contact column.
    Modify contacts
  4. In the Modify Contact dialog box, select alert contacts.
    To add a contact, click + Add Receiver, and then specify the email address, mobile phone number, and position of the contact. Only the Alibaba Cloud account owner can specify mobile phone numbers for contacts.
    Note
    • The system sends a verification link to the specified mobile phone number and email address of the newly added contact. The contact can receive alert notifications only after clicking the verification link to confirm the contact information.
    • You must specify at least one alert notification receiver.
    • Alert notifications can be sent to the specified receivers by email by default. Other notification methods are not supported.
    • A maximum of 50 alert notifications can be sent to each or email address per day.

Template variables

You must set Content for each notification method. In the notification content, you can reference some template variables in the ${fieldName} format for the alert. When sending an alert notification, Log Service replaces the template variables referenced in the Content field with real values. For example, it replaces ${Project} with the name of the project to which the alert belongs.
Note You must reference valid variables. If a referenced variable does not exist or is invalid, Log Service processes the variable as a null string. If the value of a referenced variable is of the object type, the value is converted and displayed as a JSON string.
The following table describes all available variables and how to reference these variables for an alert.
Variable Description Example Reference example
Aliuid The ID of the Alibaba Cloud account to which the project belongs. 1234567890 The alert configured by the user ${Aliuid} is triggered.
Project The project to which the alert belongs. my-project The alert configured in the project ${Project} is triggered.
AlertID The unique ID of the alert. 0fdd88063a611aa114938f9371daeeb6-1671a52eb23 The ID of the alert is ${AlertID}.
AlertName The name of the alert. The name must be unique in a project. alert-1542111415-153472 The alert ${AlertName} is triggered.
AlertDisplayName The display name of the alert. My alert The alert ${AlertDisplayName} is triggered.
Condition The conditional expression that triggers the alert. Each variable in the conditional expression is replaced with the value that triggers the alert. The value is enclosed in brackets []. [5] > 1 The conditional expression that triggers the alert is ${Condition}.
RawCondition The original conditional expression that triggers the alert. Variables in the conditional expression are not replaced. count > 1 The original conditional expression that triggers the alert is ${RawCondition}.
Dashboard The name of the dashboard with which the alert is associated. mydashboard The alert is associated with the dashboard ${Dashboard}.
DashboardUrl The URL of the dashboard with which the alert is associated. https://sls.console.aliyun.com/next/project/myproject/dashboard/mydashboard The URL of the dashboard associated with the alert is ${DashboardUrl}.
FireTime The time when the alert is triggered. 2018-01-02 15:04:05 The alert is triggered at ${FireTime}.
FullResultUrl The URL used to query the history records that the alert was triggered. https://sls.console.aliyun.com/next/project/my-project/logsearch/internal-alert-history?endTime=1544083998&queryString=AlertID%3A9155ea1ec10167985519fccede4d5fc7-1678293caad&queryTimeType=99&startTime=1544083968 Click ${FullResultUrl} to view alert details.
Results The parameters and results of each log data query. The value is of the array type. For more information, see Alert log fields.
[
  {
    "EndTime": 1542507580,
    "FireResult": {
      "__time__": "1542453580",
      "count": "0"
    },
    "LogStore": "test-logstore",
    "Query": "* | SELECT COUNT(*) as count",
    "RawResultCount": 1,
    "RawResults": [
      {
        "__time__": "1542453580",
        "count": "0"
      }
    ],
    "StartTime": 1542453580
  }
]
The first query starts at ${Results[0].StartTime} and ends at ${Results[0].EndTime}. The alert has been triggered ${Results[0].FireResult.count} times.
Note In this example, the digit 0 indicates the sequence number of the chart query or analysis statement. For more information, see How can I check the sequence number of a chart?