Event Filters
Examples:
sources:
- name: azure_service_bus
ansible.eda.azure_service_bus:
conn_str: "{{connection_str}}"
queue_name: "{{queue_name}}"
filters:
- json_filter:
include_keys: ['clone_url']
exclude_keys: ['*_url', '_links', 'base', 'sender', 'owner', 'user']
- dashes_to_underscores:
Builtin Event Filters
ansible-rulebook provides the following builtin event filters:
eda.builtin.insert_meta_info
eda.builtin.event_splitter
eda.builtin.dashes_to_underscores
eda.builtin.json_filter
eda.builtin.normalize_keys
eda.builtin.insert_hosts_to_meta
eda.builtin.insert_meta_info
event = { ..., 'meta': {'source': {'name': 'azure_service_bus',
'type': 'ansible.eda.azure_service_bus'},
'received_at': '2023-03-23T19:11:15.802274Z',
'uuid': 'eb7de03f-6f8f-4943-b69e-3c90db346edf'}
}
eda.builtin.event_splitter
Name |
Description |
Required |
|---|---|---|
splitter_key |
The nested key which stores the array of events. You can use the dot delimiter to specify the path e.g incident.alerts |
Yes |
attribute_key_map |
If you need to add additional attributes from the parent nodes into the event, specified as a dictionary |
No |
extras |
If you need to add static attributes into the event, specified as a dictionary |
No |
raise_error |
true or false. If the splitter_key is missing we can stop the source by setting raise_error as true. Default is false, we would return the event as it is if the splitter_key is missing. |
No |
Examples:
sources:
- name: my_prometheus
ansible.eda.alertmanager:
...
filters:
- eda.builtin.event_splitter:
splitter_key: alerts
attributes_key_map:
header: header
hosts: labels.instance
extras:
region: us-east
sources:
- name: my_bigpanda
...big_panda...:
...
filters:
- eda.builtin.event_splitter:
splitter_key: incident.alerts
attributes_key_map:
id: incident.id
active: incident.active
severity: incident.severity
status: incident.status
environments: incident.environments
eda.builtin.dashes_to_underscores
Changes dashes in event keys to underscores. For instance, the key server-name becomes server_name.
This filter processes all dictionary keys recursively, including those nested in lists. It takes one parameter:
Name |
Description |
Required |
|---|---|---|
overwrite |
Overwrite values if there is a key collision when converting dashes to underscores. Default: true |
No |
Examples:
sources:
- name: my_webhook
eda.builtin.webhook:
host: 0.0.0.0
port: 5000
filters:
- eda.builtin.dashes_to_underscores:
overwrite: false
# Input event
{
"server-name": "web01",
"app-version": "1.0"
}
# Output event
{
"server_name": "web01",
"app_version": "1.0"
}
eda.builtin.json_filter
Filters keys from events based on include/exclude patterns. The include_keys parameter protects keys
from being excluded (it doesn’t act as a whitelist). Include patterns override exclude patterns.
Name |
Description |
Required |
|---|---|---|
exclude_keys |
List of key patterns to remove (supports wildcards like |
No |
include_keys |
List of key patterns to keep even if they match exclude patterns |
No |
Examples:
sources:
- name: my_source
eda.builtin.webhook:
host: 0.0.0.0
port: 5000
filters:
- eda.builtin.json_filter:
exclude_keys:
- 'metadata'
- 'internal_*'
include_keys:
- 'internal_id'
# Input event
{
"data": "important",
"metadata": "remove",
"internal_debug": "remove",
"internal_id": "keep"
}
# Output event (internal_id kept despite matching internal_*)
{
"data": "important",
"internal_id": "keep"
}
eda.builtin.normalize_keys
Normalizes keys by replacing non-alphanumeric characters with underscores. Consecutive special characters
are coalesced into a single underscore. For example, server.name becomes server_name and
server--name becomes server_name.
Name |
Description |
Required |
|---|---|---|
overwrite |
Overwrite values if there is a key collision after normalization. Default: true |
No |
Examples:
sources:
- name: my_source
eda.builtin.webhook:
host: 0.0.0.0
port: 5000
filters:
- eda.builtin.normalize_keys:
# Input event
{
"server.name": "web01",
"app@version": "1.0",
"data--key": "value"
}
# Output event
{
"server_name": "web01",
"app_version": "1.0",
"data_key": "value"
}
eda.builtin.insert_hosts_to_meta
Extracts hosts from event data and inserts them into the meta dictionary. In ansible-rulebook, this limits actions to run only on the specified hosts in the meta dict.
Name |
Description |
Required |
|---|---|---|
host_path |
The JSON path inside the event data to find hosts (uses dot notation) |
Yes |
path_separator |
The separator to interpret host_path. Default: “.” |
No |
host_separator |
Separator to split host string if it contains multiple hosts |
No |
raise_error |
Raise error if host_path doesn’t exist. Recommended for development. Default: false |
No |
log_error |
Log error if host_path doesn’t exist. Default: true |
No |
Examples:
sources:
- name: my_alertmanager
ansible.eda.alertmanager:
host: 0.0.0.0
port: 5050
filters:
- eda.builtin.insert_hosts_to_meta:
host_path: "alert.target"
path_separator: "."
raise_error: true
# Input event
{
"alert": {
"target": "server1.example.com",
"severity": "critical"
}
}
# Output event
{
"alert": {
"target": "server1.example.com",
"severity": "critical"
},
"meta": {
"hosts": ["server1.example.com"]
}
}