Skip to content

Commit

Permalink
Making the excluded_messages field optional (#19253)
Browse files Browse the repository at this point in the history
* making excluded_messages optional

* lint

* Update vsphere/datadog_checks/vsphere/config.py

Co-authored-by: Sarah Witt <[email protected]>

---------

Co-authored-by: Sarah Witt <[email protected]>
  • Loading branch information
rahulkaukuntla and sarah-witt authored Dec 11, 2024
1 parent 35589a7 commit 724567b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions vsphere/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ files:
description: |
The events that should be collected by the vSphere integration.
The "event" specifies the event type you want to include, and the "excluded_messages" is a list of
messages of that event type you do not want to collect. For example, if the key
The "event" specifies the event type you want to include, and optionally, the "excluded_messages" is
a list of messages of that event type you do not want to collect. For example, if the key
is 'AlarmStatusChangedEvent' and the values for this key are 'Gray to Green' and 'Green to Gray',
then all events named 'AlarmStatusChangedEvent' that don't have the message 'Gray to Green'
and 'Green to Gray' will be included.
Expand Down
2 changes: 1 addition & 1 deletion vsphere/datadog_checks/vsphere/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(self, instance, init_config, log):
self.exclude_filters = {}
for item in self.include_events:
event_name = item["event"]
excluded_messages = [r'{}'.format(msg) for msg in item["excluded_messages"]]
excluded_messages = [r'{}'.format(msg) for msg in item.get("excluded_messages", [])]
self.exclude_filters[event_name] = excluded_messages

# Since `collect_per_instance_filters` have the same structure as `metric_filters` we use the same parser
Expand Down
4 changes: 2 additions & 2 deletions vsphere/datadog_checks/vsphere/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ instances:
## @param include_events - list of mappings - optional
## The events that should be collected by the vSphere integration.
##
## The "event" specifies the event type you want to include, and the "excluded_messages" is a list of
## messages of that event type you do not want to collect. For example, if the key
## The "event" specifies the event type you want to include, and optionally, the "excluded_messages" is
## a list of messages of that event type you do not want to collect. For example, if the key
## is 'AlarmStatusChangedEvent' and the values for this key are 'Gray to Green' and 'Green to Gray',
## then all events named 'AlarmStatusChangedEvent' that don't have the message 'Gray to Green'
## and 'Green to Gray' will be included.
Expand Down
24 changes: 24 additions & 0 deletions vsphere/tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,30 @@ def test_include_events_ok(aggregator, realtime_instance, dd_run_check, mock_api
assert aggregator.events[0]['msg_title'] == "[Triggered] alarm1 on VM vm1 is now red"


@pytest.mark.usefixtures('mock_type', 'mock_threadpool', 'mock_rest_api')
def test_include_events_no_excluded_message(aggregator, realtime_instance, dd_run_check, mock_api):
realtime_instance['include_events'] = [{"event": "AlarmStatusChangedEvent"}]
check = VSphereCheck('vsphere', {}, [realtime_instance])
event1 = vim.event.AlarmStatusChangedEvent()
event1.createdTime = dt.datetime.now()
event1.entity = vim.event.ManagedEntityEventArgument()
event1.entity.entity = vim.VirtualMachine(moId="vm1")
event1.entity.name = "vm1"
event1.alarm = vim.event.AlarmEventArgument()
event1.alarm.name = "alarm1"
setattr(event1, 'from', 'green')
event1.to = 'red'
event1.datacenter = vim.event.DatacenterEventArgument()
event1.datacenter.name = "dc1"
event1.fullFormattedMessage = "Green to Red"
mock_api.side_effect = mock_api_with_events([event1])

dd_run_check(check)

assert len(aggregator.events) == 1
assert aggregator.events[0]['msg_title'] == "[Triggered] alarm1 on VM vm1 is now red"


@pytest.mark.usefixtures('mock_type', 'mock_threadpool', 'mock_rest_api')
def test_include_events_filtered(aggregator, realtime_instance, dd_run_check, mock_api):
realtime_instance['include_events'] = [
Expand Down

0 comments on commit 724567b

Please sign in to comment.