All Products
Search
Document Center

Cloud Config:Use EventBridge to send the events delivered to MNS to DingTalk

Last Updated:Jun 20, 2023

This topic describes how to use EventBridge to send the events that are delivered to Message Service (MNS) to DingTalk.

Prerequisites

Background information

You can deliver Cloud Config events to the following channels: Log Service, Object Storage Service (OSS), and MNS. You can use the event processing and delivery features provided by EventBridge to deliver evaluation events to other channels in a specified format. For example, you can deliver configuration changes or non-compliance events of resources to DingTalk, Message Queue, Function Compute, Short Message Service, or Alibaba Mail. In this topic, a resource non-compliance event is delivered. An EventBridge event flow is used to convert the detected non-compliant resource into an event and send the event to DingTalk in the specified format.

Step 1: Create an MNS topic and queue

  1. Create an MNS topic.

    For more information, see Create a topic.

  2. Create an MNS queue.

    For more information, see Create a queue.

  3. You can create a subscription for a topic. This way, the messages that are sent to the topic are pushed to the queue that subscribes to the topic.

    For more information, see Create and use subscriptions.

Note

If you have already created an MNS topic and queue, proceed to the next step.

Step 2: Configure settings to deliver events to MNS

  1. Create a Cloud Config rule.

    For more information, see Create a rule based on a managed rule or Create a custom rule.

  2. Configure the settings to deliver events to MNS.

    For more information, see Deliver resource data to an MNS topic.

Note

If you have created a rule in Cloud Config and configured data delivery to MNS, proceed to the next step.

Step 3: Create an EventBridge event bus and configure event delivery

  1. Log on to the EventBridge console.

  2. In the left-side navigation pane, click Event Buses.

  3. In the top navigation pane, select a region.

  4. In the Custom Event Buses section, click Quickly Create.

  5. In the Create Custom Event Bus panel, set the parameters.

    1. In the Event Bus step, enter the name of the custom event bus and description, and then click Next Step.

    2. In the Event Source step, set the following parameters and click Next Step.

      1. Specify Event Source Name. For example, enter noncompliant.event.

      2. Select Message Service (MNS) from the Event Provider drop-down list.

      3. Specify Queue Name.

      4. Select Enable Base64 Decoding.

    3. In the Event Rule step, set the following parameters and click Next Step.

      1. Specify Event Rule Name. For example, enter noncompliant-resource-rule.

      2. Configure the Pattern Content of the event bus to filter out irrelevant events.

        The following pattern content indicates that only events with the name noncompliant.event are delivered to the event target. For more information, see Event patterns.

        {
            "source": [
                "noncompliant.event"
            ]
        }
    4. In the Event Target step, set the following parameters and click Create.

      1. Select DingTalk acs.dingtalk from the Service Type drop-down list.

      2. Specify the Address and Secret Key of the DingTalk group chat.

      3. Configure Pushed Content.

        Configure a template to convert events and push the events to the event target. The following parameters and template indicate that the resource ARN and rule name are parsed from non-compliance events and pushed to DingTalk. For more information, see Event transformation.

      /**Variables**/
      {
        "resourceArn": "$.data.messageBody.evaluationResultIdentifier.evaluationResultQualifier.resourceArn",
        "configRuleName": "$.data.messageBody.evaluationResultIdentifier.evaluationResultQualifier.configRuleName"
      }
      /**Template**/
      {
        "msgtype": "text", 
        "text": {
            "content": "Resource non-compliance notification: Resource: ${resourceArn}. Rule name: ${configRuleName}"
        }
      }

Step 4: Verify the result

  1. Log on to the Cloud Config console.

  2. In the left-side navigation pane, choose Compliance & Audit > Rules.

  3. On the Rules page, find the rule, click the image..png icon in the Actions column, and then click Re-evaluate.

  4. Go to the DingTalk group chat configured in Step 3 and view chatbot notifications.

    If the DingTalk group chat has resource non-compliance notifications, the configurations are complete.

FAQ

Can I set the MNS topic that is used when I configure event delivery to MNS as the event source of the event bus?

No. EventBridge event buses can use only MNS queues as event sources. You can configure a queue for the MNS topic and use the queue as the MNS event source.

I have configured an EventBridge event flow and manually execute evaluation in the Cloud Config console. Why does the DingTalk group chat fails to receive notifications?

  1. Perform the following steps to troubleshoot the issue in the Cloud Config console to ensure that no non-compliant resource exists:

    1. Log on to the Cloud Config console.

    2. In the left-side navigation pane, choose Compliance & Audit > Rules.

      View the evaluation results of the rules to ensure that no non-compliant resource exists.

  2. Perform the following steps to troubleshoot the issue in the EventBridge console to ensure that the event is delivered:

    1. Log on to the EventBridge console.

    2. In the left-side navigation pane, click Event Buses.

    3. On the Event Buses page, find the event bus and click Event Tracking in the Actions column.

      Query events by time range and ensure that data exists in the event source.

    4. Find the event that you want to view and click Event Detail in the Actions column.

      In the Event Detail dialog box, make sure that the event is delivered.

What do I do if EventBridge events fail to be delivered?

  • If the [500]java.lang.RuntimeExceptionjava.lang.RuntimeExceptionjava.lang.RuntimeException is missing parameter JSON message appears, perform the following steps:

    Make sure that the key-value pair of the $.data object of the event content does not contain quotation marks. Otherwise, after the variable is replaced, the original JSON string is truncated by the quotation marks and becomes invalid. You can use the escape tool jsonEscape provided by the system to modify the configuration of the rule template. In the following example, the value of the variable configRuleName contains quotation marks, and jsonEscape is used as an escape character in the template.

    /**Variables**/
    {
      "resourceArn": "$.data.messageBody.evaluationResultIdentifier.evaluationResultQualifier.resourceArn",
      "configRuleName": "$.data.messageBody.evaluationResultIdentifier.evaluationResultQualifier.configRuleName"
    }
    /**Template**/
    {
      "msgtype": "text", 
      "text": {
          "content": "Resource non-compliance notification: Resource: ${resourceArn}. Rule name: ${jsonEscape(configRuleName)}"
      }
    }
  • If the [500]java.lang.RuntimeExceptionjava.lang.RuntimeExceptionjava.lang.RuntimeExceptionsendtoofast,exceed20timesperminute message appears, perform the following steps to troubleshoot the issue:

    DingTalk limits the frequency at which custom chatbots can send messages. Each chatbot can send a maximum of 20 messages to a DingTalk group chat per minute. If the number of DingTalk messages exceeds 20, throttling is enabled for 10 minutes. If a large number of messages are sent after alerts are triggered, such as system monitoring alerts, you can integrate these messages and use Markdown to send them to DingTalk group chats in the form of summaries.