Description
ACS::EventTrigger automatically performs event-driven O&M operations. After a template containing this action is executed, the execution enters the Waiting state. When the monitored event occurs, the execution enters the Running state and immediately runs the subsequent tasks defined in the template. For example, when Operation Orchestration Service (OOS) receives a preemptible instance interruption event notification, OOS removes the interrupted preemptible instance from the Server Load Balancer (SLB) backend server list.
OOS monitors events such as cloud service status notifications, operational events, and business exceptions. You can filter events by CloudOps Orchestration Service name, event name, event level, and event details.
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 filter rules and output for monitored events, understand the event notification format. Event notifications are in JSON format. The outer layer contains common attributes, and the content section contains event details. The following example uses the same format as CloudMonitor event notifications. For more information, 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 cloud service name. For valid values, refer to the Event notification format section or call the CloudMonitor DescribeSystemEventMetaList API. -
Name: The event name. For valid values, refer to the Event notification format section or call the CloudMonitor DescribeSystemEventMetaList API. -
Level: the level of the event. Valid values: CRITICAL, WARN, INFO, and *. A value of * specifies all levels of events.
-
Content: The event details. For the attributes and values that you can filter by, see the Event notification format section.
-
Event outputs
Define the Outputs of the task to pass event data to subsequent tasks. The ValueSelector uses a jq expression to extract data from the JSON-formatted event notification. For the notification structure, see the Event notification format section.
Examples
The following example starts 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"
}
}
}