All Products
Search
Document Center

CloudOps Orchestration Service:ACS::EventTrigger

Last Updated:Dec 27, 2023

Features

The ACS::EventTrigger action can be used to automatically perform event-driven O&M operations. After a template containing this action is created and executed, the execution is in the Waiting status. When the event trigger detects that the monitored event occurs, the execution status changes to running and the subsequent tasks defined in the template are executed immediately. For example, CloudOps Orchestration Service (OOS) removes a preemptible instance from the backend server list of Server Load Balancer (SLB) after receiving the notification of the Instance:PreemptibleInstanceInterruption event. For more information, see Overview of event notifications.

OOS can monitor the cloud product status, O&M events, and business exceptions. You can filter events by cloud product name, event name, event level, event details, and other attributes to achieve accurate monitoring and timely response.

Restrictions

The trigger actions have the following restrictions:

  • Only one trigger action is allowed for one template.

  • The task where a trigger action resides must be defined as the first task in the Tasks parameter of the template.

  • Trigger actions are not allowed for embedded templates.

Syntax

  • YAML format

Tasks:
  - Name: taskName # The name of the task.
    Action: 'ACS::EventTrigger'
    Properties:
      Product: productName1 # The name of the cloud product, such as ECS. Type: String.
      Name:          # The name of the event, such as ["Instance:StateChange"]. Type: List.
        - eventName1
      Level:        # The level of the event, such as ["INFO"]. Type: List.
        - eventLevel1
      Content:  # The details of the event, such as { "state":["Stopped"] }. Type: Map.
        contenAttrKey1: # The name of the attribute for filtering event details.
          - value1 # The value of the attribute for filtering event details.
    Outputs: # Optional. The output of the task.
      outputParameterName1: # The name of the output parameter. The name can contain letters, digits, underscores (_), and hyphens (-). It can be up to 200 characters in length.
        ValueSelector: "jq selector" # The jQuery selector for selecting the required JSON data. For example, when the task receives event notifications in JSON format, the jQuery selector extracts the required information, such as ".content.resourceId", from the JSON data.
        Type: type1 # Optional. The type of the output parameter. The valid values include the basic parameter types supported by the YAML or JSON format, such as String, Number, Boolean, List or Array, and Object. Default value: String.
  • JSON format (For more information, see the parameter description for the YAML format.)

{
    "Tasks": [
        {
            "Name": "taskName",
            "Action": "ACS::EventTrigger",
            "Properties": {
                "Product": "productName1",
                "Name": [
                    "eventName1"
                ],
                "Level": [
                    "eventLevel1"
                ],
                "Content": {
                    "contenAttrKey1": [
                        "value1"
                    ]
                }
            },
            "Outputs": {
                "outputParameterName1": {
                    "ValueSelector": "jq selector",
                    "Type": "type1"
                }
            }
        }
    ]
}

Event notification format

Before configuring the filter rules and output for monitored events, you need to understand the notification format of monitored events. The event notification is in JSON format. The outer layer includes the common attributes, and the content section includes the event details, as shown in the following example. The format is the same as that of cloud product events notification. For more information about the formats of different event notifications, see Cloud product events.

Example

{
    "product": "ECS",
    "resourceId": "acs:ecs:cn-shanghai:1612345678890:instance/i-abcdef",
    "level": "WARN",
    "instanceName": "instanceName",
    "regionId": "cn-hangzhou",
    "name": "Instance:PreemptibleInstanceInterruption",
    "content": {
        "instanceId": "i-abcdef",
        "action": "delete"
    }
}

Event filtering

  • Filter rules

    • Data matching is performed only when the event contains all the filter condition attributes and the embedding structure of the filter condition attributes are the same as that of the event attributes.

    • Data matching is case-sensitive.

    • If the value of a filter condition attribute is an array, the array must contain at least one element. If any element in the array matches the value of the corresponding event attribute, this filter condition attribute meets the requirements.

    • Assume that the values of a filter condition attribute and the corresponding event attribute are both arrays. If any element in the array of the filter condition attribute matches any element in the array of the event attribute, this filter condition attribute meets the requirements.

    • An event is triggered when the values of all attributes match the values of the corresponding event attributes.

  • Attributes that can be defined

    • Product: the name of the cloud product. For more information about the value, see Event notification format in this topic. You can also call the DescribeSystemEventMetaList operation to obtain the value.

    • Name: the name of the event. For more information about the value, see Event notification format in this topic. You can also call the DescribeSystemEventMetaList operation to obtain the value.

    • Level: the level of the event. Valid values: CRITICAL, WARN, INFO, and . Among them, the value indicates all levels of events.

    • Content: the details of the event. For more information about the definitions and values of the filter condition attributes, see Event notification format in this topic.

Event outputs

You can define the Outputs parameter of a task to determine the output information of the corresponding event. The output information can be used by subsequent tasks. The ValueSelector parameter in Outputs is the same as that for normal tasks. It is used to filter event notifications in JSON format. For more information, see Event notification format in this topic.

Example

The following template is used to start an ECS instance immediately after it is stopped:

  • YAML format

---
FormatVersion: OOS-2019-06-01
Description: Start ECS instance when instance is stopped.
Parameters:
  OOSAssumeRole:
    Description: The RAM role to be assumed by OOS.
    Type: String
    Default: OOSServiceRole
RamRole: '{{OOSAssumeRole}}'
Tasks:
  - Name: whenInstanceStopped
    Action: 'ACS::EventTrigger'
    Properties:
      Product: ECS
      Name:
        - 'Instance:StateChange'
      Level:
        - INFO
      Content:
        state:
          - Stopped
    Outputs:
      InstanceId:
        ValueSelector: .content.resourceId
        Type: String
  - Name: startInstance
    Action: 'ACS::ExecuteAPI'
    Properties:
      Service: ECS
      API: StartInstance
      Parameters:
        InstanceId: '{{ whenInstanceStopped.InstanceId }}'
    Description: start instance.
Outputs:
  InstanceId:
    Value: '{{ whenInstanceStopped.InstanceId }}'
    Type: String
  • JSON format

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "Start ECS instance when instance is stopped.",
  "Parameters": {
    "OOSAssumeRole": {
      "Description": "The RAM role to be assumed by OOS.",
      "Type": "String",
      "Default": "OOSServiceRole"
    }
  },
  "RamRole": "{{OOSAssumeRole}}",
  "Tasks": [
    {
      "Name": "whenInstanceStopped",
      "Action": "ACS::EventTrigger",
      "Properties": {
        "Product": "ECS",
        "Name": [
          "Instance:StateChange"
        ],
        "Level": [
          "INFO"
        ],
        "Content": {
          "state": [
            "Stopped"
          ]
        }
      },
      "Outputs": {
        "InstanceId": {
          "ValueSelector": ".content.resourceId",
          "Type": "String"
        }
      }
    },
    {
      "Name": "startInstance",
      "Action": "ACS::ExecuteAPI",
      "Properties": {
        "Service": "ECS",
        "API": "StartInstance",
        "Parameters": {
          "InstanceId": "{{ whenInstanceStopped.InstanceId }}"
        }
      },
      "Description": "start instance."
    }
  ],
  "Outputs": {
    "InstanceId": {
      "Value": "{{ whenInstanceStopped.InstanceId }}",
      "Type": "String"
    }
  }
}