Managing Rules for Events
This topic describes how to manage rules for the Events service. For more information about Events, see Overview of Events.
Prerequisites for Creating Rules
-
Action resources: You must have resources already set up to specify as an action. The Events service invokes the action specified in the rule by delivering the event message to action resources, which can include topics , streams, or functions. Every rule must have at least one action. The Events service can invoke any of the following services by delivering an event message for processing:
-
IAM policies: To manage or list rules, you must be given the required type of access in a policy written by an administrator, whether you're using the Console or the REST API with an SDK, CLI, or other tool. If you try to perform a task and get a message that you don’t have permission or are unauthorized, confirm with your administrator the type of access you've been granted and which compartment you should work in. For more information, see Events and IAM Policies.
- Event messages: To create rules, the resources you want to monitor with the rule must emit events. For more information, see Services that Produce Events.
Working with Rules
Each rule can have a maximum of 10 actions.
A typical workflow for setting up rule might follow this pattern:
- Identify action resources
Set up or identify whatever action resources you intend to use with the rule. For example, you might set up a Notifications topic and create subscriptions for the DevOps team so that they are notified when backups complete. If a topic already exists, you can use it instead of creating a topic. The resources you specify for actions do not have to be in the same compartment as the rule.
- Plan filtering
Ensure the resources that you want to monitor emit events to the Events service and plan your pattern matching strategy. For example, you might want to monitor backups on Autonomous Database for Analytics and Data Warehousing instances in the ABC compartment. Ensure Autonomous Database for Analytics and Data Warehousing instances emit an event type you can use to create the automation you require. Review the example JSON event to determine the best way to identify those resources in filters. See Matching Events with Filters and Services that Produce Events.
- Create the rule
Rules apply to events in the compartment in which you create them and any child compartments. Create a rule in the compartment with the resource you want to monitor and specify where to deliver matching events. For example, in the ABC compartment, you might create a rule that filters for Autonomous Database for Analytics and Data Warehousing backup events. Since Events has no requirement about the location of action resources, you could specify a topic in the XYZ compartment as the resource to deliver any matching events.
Managing Tags for Rules
Tags and Event Filtering
With Events, you can also use tags to target resources in your tenancy. You target resources by adding the tag to a filter in a rule. A filter tag helps you hone automation by targeting only resources that contain a particular tag. For example, let's say you have dozens of Database instances in your tenancy, but only a few of the most critical of these instances have the tag "Operations." You could create a rule that triggers a particular action for resources that only contain the "Operations" tag.
Policy for working with filter tags is no different from policy for working with tags.
Move Rules to a Different Compartment
You can move rules from one compartment to another. When you move a rule to a new compartment, you stop monitoring events from resources in the current compartment and begin monitoring events in the new compartment (and any child compartments). After you move the rule to the new compartment, inherent policies apply immediately and affect access to the rules through the Console. Moving rules doesn't affect access by the Events service to actions defined in rules. For more information, see Working with Compartments.
Monitoring Rules
You can monitor the health, capacity, and performance of your Oracle Cloud Infrastructure resources by using metrics, alarms, and notifications. For more information, see Monitoring and Notifications.
For more information about monitoring the rules you create, see Events Metrics.
Object Events and the Events Service
Using the Console
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click Create
Rule.
Events compares the rules you create in this compartment to event messages emitted from resources in this compartment and any child compartments.
- Enter the following.
- Display Name: Specify a friendly name for the rule. You can change this name later. Avoid entering confidential information.
- Description: Specify a description of what the rule does. You can change this description later.
- In Rule Conditions, create a filter: To add an event type
- Select Event Type from Condition.
- Select a Service Name.
- In Event Type, select one or more event types for this service.
- Click + Another Condition and select Event Type to add
event types for a different service.
This filter will match events of the event types you specify.
To add an attribute
You must first have already created an event type rule condition before you can add an attribute.
- After adding an event type, click + Another Condition.
- Select Attribute from Condition.
- Select an Attribute Name.
- Select or enter attribute values from Attribute Values. Attribute
values are optional.
This filter will match events of the events types with the attributes you specify.
To add a filter tag- Select Filter Tag
- Select a Tag namespace.
To specify a free-form tag, select None (add a free-form tag).
- Select a Tag key.
- Enter a Tag value. Tag values are optional.
- Click + Another Condition and select Filter Tag to add
another filter tag.
This filter will match events with the tags you specify.
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.
To validate this rule
You can only evaluate a rule against one event type at a time. To test different event types, repeat these steps as necessary.
- Click Validate Rule. The Validate Rule panel opens.
- In Service Name, select a service if necessary.
- In Event Type, select an event type, if necessary. A example event appears based on the selections you made. Edit the values in the event to match the values for any attributes and tags you added to your rule. For more information, see Contents of an Event Message.
- Click Check if Example Event Matches Rule. If the rule doesn't match,
use the rule editor to modify any of the following:
- 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.
- Click Cancel.
To view reference events
- Click View example events (JSON). The View Example Events panel opens.
- In Service Name, select a service if necessary.
- In Event Type, select an event type, if necessary. An example event appears based on the selections you made. Use the events viewer to browse reference events.
- Click Done.
For more information, see Contents of an Event Message and Matching Events with Filters.
- In Actions, specify the actions resources to trigger when the filter finds a match:
To select a topic
- Select Notifications.
- Select the Notifications Compartment.
- Select the Topic.
- Click + Another Action and select Notifications to add another topic.
To select a stream- Select Streaming.
- Select the Stream Compartment.
- Select the Stream.
- Click + Another Action and select Streaming to add another stream.
To select a function- Select Functions.
- Select the Function Compartment.
- Select a Function Application.
- Select the Function.
- Click + Another Action and select Functions to add another function.
- Click Create Rule.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment that has the rule you want to edit.
- For the rule you want to edit, click the Actions menu, and then click Edit.
- Make your changes and click Save changes.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment that has the rule you want to work with.
- For the rule, you want change, click the Actions menu, and then take one
of the following actions:
- Click Disable
- Click Enable
- Confirm when prompted.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- In the Scope section, select a compartment.
- Find the rule in the list, click the the Actions menu, and then click Move Resource.
- Choose the destination compartment from the list.
- Click Move Resource.
You can only evaluate a rule against one event type at a time. Repeat as necessary to test different event types.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to test.
- Click Validate Rule.
- Take one or more of the following actions:
- If there are no event types in the rule, select the service and event type you want to test.
- If you want to test a different event type than the one selected by default, select the service and event type you want to test.
-
If you added attribute values or filter tags to the rule, edit the example data in the event to match the values in your rule.
- Click Check if Example Event Matches Rule.
For more information, see Matching Events with Filters and Contents of an Event Message.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose the Compartment that has rule you want to delete.
- For the rule you want to delete, click the Actions menu , and then click Delete.
- Confirm when prompted.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Actions.
- Click Add.
-
The Add Action box appears. Configure the action resources:
To select a topic- Select Notifications.
- Select the Notifications Compartment.
- Select the Topic.
To select a stream- Select Streaming.
- Select the Stream Compartment.
- Select the Stream.
To select a function- Select Functions.
- Select the Function Compartment.
- Select a Function Application.
- Select the Function.
- Action State: Select to enable the action. Clear to disable.
-
- Click Add Action.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Actions.
- Select an action.
- Go to Actions and click Edit. The Edit Action box appears.
- Make your changes and click Save Changes.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Actions.
- Select an action.
- Go to Actions and specify Enable or Disable.
- Confirm when prompted.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Actions.
- Select an action.
- Go to Actions and click Remove.
- Confirm when prompted.
Each rule must have one action.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Click Add Event Type.
- In Service Name, select a service.
- In Event Type, select an event type for this service.
- Click Add Event Type.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Select an event type.
- Click Edit. The Edit Event Type box appears.
- Make your changes and click Save Changes.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Select the check box next to the event types you want to remove.Tip
To select the entire list, select the check box in the header row. - Click Remove.
- Confirm when prompted.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Click Add Attribute. The Add Attribute box appears. Configure the attribute:
-
Attribute Name: Specify an attribute or tag to narrow matching results.
- Select an attribute name. The list of attribute names is based on the event types you selected. If you select no event types, you cannot add an attribute.
-
If you specify an attribute here, you limit the events that match this rule.
-
Attribute Values: Specify one or more values for the attribute name.
- Enter a value. As you type, the value appears under the field with
(New) appended. Select the value with (New) appended to add the
value to Attribute Values.
- Enter more values for attribute name in the same manner as before.
Here are some things to consider about attribute values:
- Use an asterisk to create a wildcard. See Examples of Wildcard Matching in Filters.
- Multiple values for an attribute name broaden your results. If any of the values you enter here match a value in an event, the rule matches. See Examples of Arrays in Filters.
- Enter a value. As you type, the value appears under the field with
(New) appended. Select the value with (New) appended to add the
value to Attribute Values.
-
- Click Add attribute.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Select an attribute.
- Click Edit. The Edit Attribute box appears.
- Make your changes and click Save Changes.
- Open the navigation menu and click Observability & Management. Under Events Service, click Rules.
- Choose a Compartment you have permission to work in, and then click the Name of the rule you want to update.
- In the Resources menu, click Event Matching.
- Select the check box next to the attributes you want to remove. Tip
To select the entire list, select the check box in the header row. - Click Remove.
- Confirm when prompted.
Using the Command Line Interface (CLI)
When you use the CLI to create a rule, you work a little differently than using the Console.
- To specify the actions for your rule, use a JSON formatted file. You create this file before you create the rule, and the file simplifies the amount of information you must type at the command line.
- To specify an event to match, use a JSON formatted string. You type this right into the console as you create the rule.
For information about using the CLI, see Command Line Interface (CLI). For a complete list of flags and options available for CLI commands, see CLI Help.
To specify the actions for your rule, use a JSON formatted file. For more information, see Advanced JSON Options.
- Create a file and add the following content. This content doesn't have to be escaped
or on a single line, it just has to contain valid
JSON.
{ "actions": [ { "actionType": "FAAS", "description": "string", "functionId": "<function_OCID>", "isEnabled": true }, { "actionType": "ONS", "description": "string", "isEnabled": true, "topicId": "<topic_OCID>" }, { "actionType": "OSS", "description": "string", "isEnabled": true, "streamId": "<stream_OCID>" } ] }
- Edit the file and remove any objects you don't want to use as an action. For
example, if you wanted to only use Notifications as an
action, then you would delete all the other objects.
{ "actions": [ { "actionType": "ONS", "description": "string", "isEnabled": true, "topicId": "<topic_OCID>" } ] }
- Edit the file and fill in any variables with actual values from
your tenancy, as shown in the following example.
{ "actions": [ { "actionType": "ONS", "description": "string", "isEnabled": true, "topicId": "<topic_OCID>" } ] }
- Add a description.
- Save the file as action.json
- To create a rule and specify Notifications as an
action, run the following command.
oci events rule create --display-name <friendly_name> --is-enabled true --condition "{}" --compartment-id <compartment_OCID> --actions file://action.json
Open a command prompt and run oci events rule create
to create a rule.
Use the following options:
display-name
indicates the name of the rule in the Consoleis-enabled
indicates whether Events should evaluate the rule.-
condition
a JSON formatted string used to indicate a pattern for event matching (see Examples for usage).Examples
The following example shows how to pass a simple condition that matches all events. Everything between the double quotes (
" "
) is a string, while the brackets{ }
indicate JSON:oci events rule create --display-name <friendly_name> --is-enabled true --condition "{}" --compartment-id <compartment_OCID> --actions file://action.json --wait-for-state=ACTIVE
To pass complex input to the CLI as a JSON string, you must enclose the entire block in double quotes. Inside the block, each double quote for the key and value strings must be escaped with a backslash (
\
) character. For example:oci events rule create --display-name <friendly_name> --is-enabled true --condition "{\"eventType\":[\"com.oraclecloud.objectstorage.createobject\"]}" --compartment-id <compartment_OCID> --actions file://action.json --wait-for-state=ACTIVE
In PowerShell, to escape double quotes, you must use two characters: The backslash (
\
) and the back tick (`
). For example, in Windows PowerShell:oci events rule create --display-name <friendly_name> --is-enabled true --condition "{\`"eventType\`":[\`"com.oraclecloud.objectstorage.createobject\`"]}" --compartment-id <compartment_OCID> --actions file://action.json --wait-for-state=ACTIVE
Tip
Thecondition
option does not support using a file to pass the JSON formatted string.For information on creating filters, see Matching Events with Filters.
compartment-id
indicates the compartment where the rule applies. Events evaluates messages from resources in this compartment and any subordinate compartments.actions
indicates the location in the local file system of the JSON formatted file you created to specify the actions for a rule.wait-for-state=
when used with ACTIVE indicates that the CLI should wait for the service to create the rule, do another GET operation, and then display the rule in the active state. Without the option, the CLI displays the rule immediately in the creating state.
For example:
oci events rule create --display-name <friendly_name> --is-enabled true
--condition <json_formatted_string> --compartment-id <compartment_OCID>
--actions <json_formatted_file> --wait-for-state=ACTIVE
Replace the values in <compartment_OCID> and <json_formatted_file> with the actual values from your tenancy and the local file system.
Open a command prompt and run oci events rule delete
to delete a single rule. For example:
oci events rule delete --rule-id <rule_OCID>
The command returns a prompt, asking for confirmation. Type y
to delete the rule.
You can get rule metadata using the CLI. The Console displays this metadata in the Rule Details tab.
Open a command prompt and run oci events rule get
to get information about a single rule. For example:
oci events rule get --rule-id <rule_OCID>
The command returns the following information:
{
"data": {
"actions": {
"actions": [
{
"action-type": "ONS",
"description": null,
"id": "ocid1.eventaction.oc1.phx.<unique_ID>",
"lifecycle-message": null,
"lifecycle-state": "ACTIVE",
"topic-id": "ocid1.onstopic.oc1.phx.<unique_ID>"
}
]
},
"compartment-id": "ocid1.compartment.oc1..<unique_ID>",
"condition": "{\n \"eventType\": [\n \"com.oraclecloud.databaseservice.autonomous.datawarehouse.backup.end\",\n \"CustomEventType\"\n ]\n}",
"defined-tags": null,
"description": null,
"display-name": "rule_name",
"freeform-tags": null,
"id": "ocid1.eventrule.oc1.phx.<unique_ID>",
"is-enabled": true,
"lifecycle-message": null,
"lifecycle-state": "ACTIVE",
"time-created": "2019-01-23T00:48:20.155000+00:00"
},
"etag": "<unique_ID>--gzip"
}
Open a command prompt and run oci events rule list
to list the rules in a compartment. For example:
oci events rule list --compartment-id <compartment_OCID>
The command returns the following information:
{
"data": [
{
"compartment-id": "ocid1.compartment.oc1..<unique_ID>",
"condition": "{}",
"description": "Example_Rule",
"display-name": "rule_1",
"id": "ocid1.eventrule.oc1.phx.<unique_ID>",
"is-enabled": true,
"lifecycle-state": "ACTIVE",
"time-created": "2019-01-22T20:10:53.562000+00:00"
},
{
"compartment-id": "ocid1.compartment.oc1..<unique_ID>",
"condition": "{}",
"description": null,
"display-name": "rule_2",
"id": "ocid1.eventrule.oc1.phx.<unique_ID>",
"is-enabled": true,
"lifecycle-state": "ACTIVE",
"time-created": "2019-01-22T20:27:25.099000+00:00"
},
...
{
"compartment-id": "ocid1.compartment.oc1..<unique_ID>",
"condition": "{\"eventType\":[\"com.oraclecloud.objectstorage.createobject\"]}",
"description": null,
"display-name": "rule_75",
"id": "ocid1.eventrule.oc1.phx.<unique_ID>",
"is-enabled": true,
"lifecycle-state": "ACTIVE",
"time-created": "2019-01-22T23:08:12.379000+00:00"
}
]
}
Open a command prompt and run oci events rule update
to update a rule.
To update the condition for a rule:
oci events rule update --rule-id <rule_OCID> --condition <json_formatted_string>
For example:
oci events rule update --rule-id ocid1.eventrule.oc1.phx.<unique_ID> --condition "{}" --wait-for-state=ACTIVE
The previous command would update the condition of the rule to use an empty JSON string. The CLI updates the rule, waits for the rule to update and change to the active state (only if you used the --wait-for-state
option), then displays the updated rule.
Use the following options to update a rule:
display-name
description
is-enabled
condition
actions
freeform-tags
defined-tags
Using the API
Use the following operations to manage rules: