This topic describes how to use a DingTalk chatbot to send event notifications to a DingTalk group. You can understand the system events related to Elastic Compute Service (ECS) instances from the DingTalk group and handle the exceptions that occur when instances are running.

Background information

Various system events may be generated when instances are running, such as events about instance state changes and O&M events. Some system events indicate that exceptions occur when instances are running. O&M personnel must be aware of the system events in a timely manner. If O&M personnel have a DingTalk group for communication, a DingTalk chatbot can be used to automatically send event notifications to the DingTalk group so that O&M personnel can handle exceptions that have occurred in a quick manner.

In the following procedure, a DingTalk chatbot and CloudMonitor are used:
  1. Create a DingTalk chatbot for a DingTalk group.
  2. Use the webhook URL of the DingTalk chatbot as the contact information of the CloudMonitor alert contact.
  3. When you configure an CloudMonitor alert rule, select the alert group that includes the corresponding alert contact to receive alert notifications.
After the preceding manual operations are complete, the following procedure is automatically performed to send a notification:
  1. When the underlying service of Alibaba Cloud detects a system event on an ECS instance (such as an event about instance state changes or an O&M event), the service pushes the event to the event center of CloudMonitor.
  2. CloudMonitor sends a notification to the alert group based on your configured alert rules. The contact information of the alert contact in this group includes the webhook URL of the DingTalk chatbot.
  3. When the DingTalk chatbot detects an event, the chatbot sends a notification in the DingTalk group.

Step 1: Create a DingTalk chatbot

A webhook URL is generated after a DingTalk chatbot is created. The webhook URL can be associated with other services such as CloudMonitor to receive notifications.

  1. Start DingTalk and go to the DingTalk group in which you want to receive alert notifications.
  2. Go to the chatbot settings page.
    1. Click the Group Settings icon (settings) in the upper-right corner of the DingTalk group.
    2. In the Group Settings panel, click Group Assistant.
    3. In the Group Assistant panel, click Add Robot.
    4. In the Add Robot section of the ChatBot dialog box, click the add icon.
    5. In the Please choose which robot to add section, click Custom.
    6. In the Robot details dialog box, click Add.
  3. Configure the DingTalk chatbot as prompted.
    You must select at least one security setting. In this example, Custom Keywords is selected for Security Settings. If you select Custom Keywords, you must enter one or more keywords. When you use the DingTalk chatbot later, the DingTalk chatbot sends alert notifications to the DingTalk group only if the notifications contain at least one of the keywords.

    For example, when CloudMonitor sends an event notification, the notification contains CloudMonitor. In this example, CloudMonitor is used as a keyword.

  4. Copy and save the webhook URL of the DingTalk chatbot.
    ding-webhook

Step 2: Associate the DingTalk chatbot with an alert rule

This section focuses on how to associate a DingTalk chatbot with an alert rule. For more information about the detailed operations, see Create an alert contact or alert contact group and Create a system event-triggered alert rule.

  1. Log on to the CloudMonitor console.
  2. Create an alert contact.
    1. In the left-side navigation pane, choose Alerts > Alert Contacts.
    2. On the Alert Contacts tab, click Create Alert Contact.
    3. In the Set Alert Contact panel, configure the alert contact as prompted.
      To associate the DingTalk bot, enter the webhook URL obtained in Step 1: Create a DingTalk chatbot in the Webhook or DingTalk Robot section.
  3. Create an alert group.
    1. Click the Alert Contact Group tab.
    2. Click Create Alert Contact Group.
    3. In the Create Alert Contact Group panel, configure the alert group as prompted.
      To associate the DingTalk chatbot, add the alert contact you created to the alert group.
  4. Create an alert rule.
    1. In the left-side navigation pane, choose Event Monitoring > System Event.
    2. Click the Event Alert tab.
    3. Click Create Alert Rule.
    4. In the Create/Modify Event Alert panel, configure the alert rule as prompted.
      Take note of the following items:
      • In this example, an event about an ECS instance state change is used. The following figure shows how to configure an alert rule for the event.
        Note The event level of the instance state change is INFO. A large number of notifications may be sent for this type of event at a high frequency. Select the event that you want to be notified of based on your business requirements.
        event-name
      • The notification methods must include the DingTalk chatbot, as shown in the following figure. alert-type

Example of an event notification in a DingTalk Group

After the settings are complete, you can change the state of an instance and check whether an event notification is received in your DingTalk group. For example, when you stop an instance, an event notification is received, as shown in the following figure. ding-notice