Creating an Events Rule

Create a rule in Events to create automation based on the state changes of resources throughout your tenancy.

    1. Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
    2. Under List Scope, select a compartment you have permission to work in.

      Events compares the rules you create in this compartment to event messages emitted from resources in this compartment and any child compartments.

    3. Click Create Rule.

    4. In the Create Rule panel, provide a friendly name for the rule and a description of what the rule does. You can change both values later. Avoid entering confidential information.

      In the Rule Conditions area, you can define filters based on event types, attributes, and tags to limit the events that trigger actions. See Matching Events with Filters. Complete the following steps to define these filters.

      Tip

      To match all events, leave this field blank. Skip to step 8.
    5. To filter events by add an event type, follow these steps.

      1. For Condition, select Event Type.
      2. Select a service.
      3. In Event Type, select one or more types of events for this the service.
      4. To add event types for a different service, click + Another Condition and select Event Type repeat the preceding steps to add event types for a different service.
    6. To further filter event types by using attributes, follow these steps. You must create an event type condition before you can add an attribute.

      1. After adding an event type, click + Another Condition.
      2. For Condition, select Attribute.
      3. Select an attribute.
      4. (Optional) In Attribute Values, select or enter values for the attribute.
    7. To filter events by using tags, follow these steps.

      Filter tags help you to hone automation by targeting only resources that contain a particular tag. If you want to use tags to organize your rules, use resource tags instead. For more information, see Managing Tags for Rules.

      1. For Condition, select Filter Tag
      2. Select a tag namespace.

        To specify a free-form tag, select None (add a free-form tag).

      3. Select a tag key.
      4. (Optional) Enter a tag value.
      5. To add another tag, click + Another Condition and repeat the preceding steps.
    8. To validate the rule based on the conditions that you specified, click Validate Rule and follow these steps in the Validate Rule panel.

      You can evaluate a rule against one event type at a time. To test different event types, repeat these steps as necessary.

      1. In Service Name, select a service.
      2. In Event Type, select an event type.

        An example event appears based on your selections you made. Edit the values in the event to match the values for any attributes and tags that you added to your rule. For more information, see Contents of an Event Message.

      3. Click Check if Example Event Matches Rule.
      4. If the rule doesn't match, use the rule editor to make the following changes as needed: 
        • Add or remove event types
        • Add or remove values or attributes
        • Add or remove tags
        • Insert wildcards

        For more information, see Matching Events with Filters.

      5. Click Cancel.
    9. To view reference (example) events, click the View example events (JSON) and follow these stes in the View Example Events panel.

      1. In Service Name, select a service.
      2. In Event Type, select an event type.

        An example event appears based on your selections. Use the events viewer to browse reference events.

      3. Click Done.

        For more information, see Contents of an Event Message and Matching Events with Filters.

    10. For Action Type, specify the resource to trigger when the filter finds a match.
      • If you select Notifications, select the compartment where the topic that you want to use is located, and then select the topic.
      • If you select Streaming, select the compartment where the stream that you want to use is located, and then select the stream.
      • If you select Functions, select the compartment where the function that you want to use is located, select the function application, and then select the function.

      To add another action, click + Another Action.

    11. Click Create Rule.
  • Use the oci events rule create command and required parameters to create a rule:

    oci events rule create --compartment-id compartment_ocid --condition condition --display-name display_name [OPTIONS]

    For a complete list of flags and variable options for CLI commands, see the Command Line Reference.

  • Run the CreateRule operation to create a rule.