All Products
Search
Document Center

ACS__EventTrigger

Last Updated: Sep 05, 2019

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, Operation 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
  1. Tasks:
  2. - Name: taskName # The name of the task.
  3. Action: 'ACS::EventTrigger'
  4. Properties:
  5. Product: productName1 # The name of the cloud product, such as ECS. Type: String.
  6. Name: # The name of the event, such as ["Instance:StateChange"]. Type: List.
  7. - eventName1
  8. Level: # The level of the event, such as ["INFO"]. Type: List.
  9. - eventLevel1
  10. Content: # The details of the event, such as { "state":["Stopped"] }. Type: Map.
  11. contenAttrKey1: # The name of the attribute for filtering event details.
  12. - value1 # The value of the attribute for filtering event details.
  13. Outputs: # Optional. The output of the task.
  14. 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.
  15. 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.
  16. 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.)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "taskName",
  5. "Action": "ACS::EventTrigger",
  6. "Properties": {
  7. "Product": "productName1",
  8. "Name": [
  9. "eventName1"
  10. ],
  11. "Level": [
  12. "eventLevel1"
  13. ],
  14. "Content": {
  15. "contenAttrKey1": [
  16. "value1"
  17. ]
  18. }
  19. },
  20. "Outputs": {
  21. "outputParameterName1": {
  22. "ValueSelector": "jq selector",
  23. "Type": "type1"
  24. }
  25. }
  26. }
  27. ]
  28. }

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

  1. {
  2. "product": "ECS",
  3. "resourceId": "acs:ecs:cn-shanghai:1612345678890:instance/i-abcdef",
  4. "level": "WARN",
  5. "instanceName": "instanceName",
  6. "regionId": "cn-hangzhou",
  7. "name": "Instance:PreemptibleInstanceInterruption",
  8. "content": {
  9. "instanceId": "i-abcdef",
  10. "action": "delete"
  11. }
  12. }

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
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Description: Start ECS instance when instance is stopped.
  4. Parameters:
  5. OOSAssumeRole:
  6. Description: The RAM role to be assumed by OOS.
  7. Type: String
  8. Default: OOSServiceRole
  9. RamRole: '{{OOSAssumeRole}}'
  10. Tasks:
  11. - Name: whenInstanceStopped
  12. Action: 'ACS::EventTrigger'
  13. Properties:
  14. Product: ECS
  15. Name:
  16. - 'Instance:StateChange'
  17. Level:
  18. - INFO
  19. Content:
  20. state:
  21. - Stopped
  22. Outputs:
  23. InstanceId:
  24. ValueSelector: .content.resourceId
  25. Type: String
  26. - Name: startInstance
  27. Action: 'ACS::ExecuteAPI'
  28. Properties:
  29. Service: ECS
  30. API: StartInstance
  31. Parameters:
  32. InstanceId: '{{ whenInstanceStopped.InstanceId }}'
  33. Description: start instance.
  34. Outputs:
  35. InstanceId:
  36. Value: '{{ whenInstanceStopped.InstanceId }}'
  37. Type: String
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "Start ECS instance when instance is stopped.",
  4. "Parameters": {
  5. "OOSAssumeRole": {
  6. "Description": "The RAM role to be assumed by OOS.",
  7. "Type": "String",
  8. "Default": "OOSServiceRole"
  9. }
  10. },
  11. "RamRole": "{{OOSAssumeRole}}",
  12. "Tasks": [
  13. {
  14. "Name": "whenInstanceStopped",
  15. "Action": "ACS::EventTrigger",
  16. "Properties": {
  17. "Product": "ECS",
  18. "Name": [
  19. "Instance:StateChange"
  20. ],
  21. "Level": [
  22. "INFO"
  23. ],
  24. "Content": {
  25. "state": [
  26. "Stopped"
  27. ]
  28. }
  29. },
  30. "Outputs": {
  31. "InstanceId": {
  32. "ValueSelector": ".content.resourceId",
  33. "Type": "String"
  34. }
  35. }
  36. },
  37. {
  38. "Name": "startInstance",
  39. "Action": "ACS::ExecuteAPI",
  40. "Properties": {
  41. "Service": "ECS",
  42. "API": "StartInstance",
  43. "Parameters": {
  44. "InstanceId": "{{ whenInstanceStopped.InstanceId }}"
  45. }
  46. },
  47. "Description": "start instance."
  48. }
  49. ],
  50. "Outputs": {
  51. "InstanceId": {
  52. "Value": "{{ whenInstanceStopped.InstanceId }}",
  53. "Type": "String"
  54. }
  55. }
  56. }