Send event notifications with a DingTalk chatbot

更新时间:
复制 MD 格式

This allows you to be notified of system events for your ECS instances in your DingTalk group, enabling you to handle exceptions promptly.

Background

ECS instances can generate various system events during their lifecycle, such as status changes and operational events. For more information, see Summary of ECS system events. Some system events indicate that an instance is not running correctly, and operations personnel must be notified of these events immediately. If your team uses a DingTalk group for daily communication, you can configure a DingTalk chatbot to automatically send event notifications to the group. This helps you respond to instance exceptions more quickly and efficiently.

This procedure uses a DingTalk chatbot and CloudMonitor.

  1. Create a DingTalk chatbot for a DingTalk group.

  2. Set the DingTalk chatbot's webhook URL as the notification method for an alert contact.

  3. In a CloudMonitor subscription policy, use an alert contact group that contains the configured alert contact.

After the setup is complete, the automated notification flow is as follows:

  1. When an Alibaba Cloud underlying service detects a system event on an ECS instance, such as a lifecycle status change or an operational event, it automatically pushes the event to the Event Center in CloudMonitor.

  2. Based on your subscription policy, CloudMonitor sends a notification to the specified alert contact group. The group's notification methods include the DingTalk chatbot's webhook URL.

  3. The DingTalk chatbot receives the event data and automatically sends a notification message to the DingTalk group.

Step 1: Create a DingTalk chatbot

Creating a DingTalk chatbot generates a unique webhook URL that you can use to receive notifications from other services, such as CloudMonitor.

For instructions on how to create a DingTalk chatbot, see Steps 1, 3, 4, 5, and 6 in Create a custom chatbot.

    Note

    As of September 1, 2023, you can no longer create custom chatbots for non-enterprise DingTalk groups. Existing custom chatbots are not affected.

    When you create the chatbot, you must add keywords. For example, because event notifications from CloudMonitor typically contain the word CloudMonitor, this example uses CloudMonitor as a keyword.

Step 2: Link chatbot to event subscription

This step highlights the operations for associating a DingTalk chatbot with a subscription policy. For more information, see Create an alert contact or an alert contact group and Manage event subscriptions (Recommended).

  1. Log on to the Cloud Monitor console.

  2. Create an alert contact.

    1. In the left-side navigation pane, choose Alerts > Alert Contact.

    2. Click Create Alert Contact.

    3. In the Set Alert Contact panel, configure the contact as prompted.

      To associate the DingTalk chatbot, enter the webhook URL that you saved in Step 1: Create a DingTalk chatbot into the DingTalk | Lark | WeCom | Slack Webhook(http|https): field.

  3. Create an alert contact group.

    1. Click the Alert Contact Group tab.

    2. Click Create Alert Contact Group.

    3. In the Create Alert Contact Group panel, configure the group as prompted.

      To associate the DingTalk chatbot, add the new alert contact to the alert contact group.

  4. Create a subscription policy.

    1. In the left-side navigation pane, choose Event Center > Event Subscription.

    2. Click the Subscription Policy tab.

    3. Click Create Subscription Policy.

    4. On the Create Subscription Policy page, configure the subscription settings as prompted.

      Note the following settings:

      • This topic uses an ECS instance status change as an example.

        Note

        The event level for instance status changes is Notification (Info). Events at this event level can be frequent, causing many notifications. In production, select only relevant events.

        image.png

      • In the notification settings, you must include the alert contact group that is associated with your DingTalk chatbot, as shown in the following figure.

        image.png

Example: DingTalk notifications

After completing the configuration, test the notification by changing an instance's status. For example, stopping an instance triggers an event notification in your DingTalk group, as shown in the following figure.ding-notice