All Products
Search
Document Center

CloudOps Orchestration Service:ACS::EventTrigger

Last Updated:May 10, 2024

Description

The ACS::EventTrigger action can be used to automatically perform event-driven O&M operations. After a template that contains the ACS::EventTrigger action is created and executed, the execution enters the Waiting state. When the event trigger detects that the monitored event occurs, the execution enters the Running state and the subsequent tasks that are defined in the template are immediately executed. For example, if Operation Orchestration Service (OOS) receives a notification of a preemptible instance interruption event, OOS removes the interrupted preemptible instance from the backend servers of Server Load Balancer (SLB).

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

Limits

The ACS::AlarmTrigger action has the following limits:

  • You can use only one ACS::AlarmTrigger action in a template.

  • The task in which the ACS::AlarmTrigger action resides must be defined as the first task in the Tasks parameter of a template.

  • You are not allowed to use the ACS::AlarmTrigger action in child templates.

Syntax

Tasks:
  - Name: taskName # The name of the task.
    Action: 'ACS::EventTrigger'
    Properties:
      Product: productName1 # The name of the cloud service, 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 that is used to filter event details.
          - value1 # The value of the attribute that is used to filter 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 data to return, such as .content.resourceId. The jQuery selector extracts information from an event notification in the JSON format. 
        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.
{
    "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 you configure the filter rules and output for monitored events, you must understand the notification format of monitored events. An event notification is in the JSON format. The outer layer contains the common attributes, and the content section contains the event details. The following sample code provides an example. In this example, the format is the same as the event notification format of CloudMonitor. For more information about the formats of different event notifications, see Alibaba Cloud service 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

    • An event is matched only when the event contains all the attributes that are used as filter conditions and the embedding structure of the filter condition attributes is the same as that of the event attributes.

    • The values of filter condition attributes are case-sensitive.

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

    • In another case, the values of a filter condition attribute and an event attribute are both arrays. If an element in the array of the filter condition attribute matches an element in the array of the event attribute, this filter condition attribute matches the event attribute.

    • An event is triggered if the values of all filter condition attributes match the values of the event attributes.

  • Attributes that can be defined as filter conditions

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

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

    • Level: the level of the event. Valid values: CRITICAL, WARN, INFO, and *. A value of * specifies all levels of events.

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

Event outputs

You can define the Tasks.Outputs attribute to determine the output information of an event. The output information can be used in subsequent tasks. The Outputs.ValueSelector attribute is the same as that for regular tasks. It is used to extract information from an event notification in the JSON format. For more information, see the Event notification format section of this topic.

Examples

The following sample code provides an example on how to start an Elastic Compute Service (ECS) instance immediately after it is stopped:

---
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
{
  "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"
    }
  }
}