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 the O&M personnel can respond to exceptions that occur 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 settings are complete, the following procedure is performed to automatically send a notification:
  1. After the underlying services of Alibaba Cloud detect that a system event occurs 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 the alert rules that you configure. The contact information of the contact in this group includes the webhook URL of the DingTalk chatbot.
  3. When the DingTalk chatbot becomes aware of an event, it automatically 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 from 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.
    You must select at least one security setting. In this example, Security Settings is set to Custom Keywords. 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 group and Create an 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 saved 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 Alerts > Alert Rules.
    2. Click the Event Alert tab.
    3. Click Create Event Alert.
    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 events at a high frequency. Select the event that you want to be notified of based on your business requirements.
        event-name
      • The notification method 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. For example, when you stop an instance, an event notification is received as shown in the following figure. ding-notice