Skip to content

Commit 724567b

Browse files
Making the excluded_messages field optional (#19253)
* making excluded_messages optional * lint * Update vsphere/datadog_checks/vsphere/config.py Co-authored-by: Sarah Witt <sarah.witt@datadoghq.com> --------- Co-authored-by: Sarah Witt <sarah.witt@datadoghq.com>
1 parent 35589a7 commit 724567b

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

vsphere/assets/configuration/spec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ files:
305305
description: |
306306
The events that should be collected by the vSphere integration.
307307
308-
The "event" specifies the event type you want to include, and the "excluded_messages" is a list of
309-
messages of that event type you do not want to collect. For example, if the key
308+
The "event" specifies the event type you want to include, and optionally, the "excluded_messages" is
309+
a list of messages of that event type you do not want to collect. For example, if the key
310310
is 'AlarmStatusChangedEvent' and the values for this key are 'Gray to Green' and 'Green to Gray',
311311
then all events named 'AlarmStatusChangedEvent' that don't have the message 'Gray to Green'
312312
and 'Green to Gray' will be included.

vsphere/datadog_checks/vsphere/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def __init__(self, instance, init_config, log):
134134
self.exclude_filters = {}
135135
for item in self.include_events:
136136
event_name = item["event"]
137-
excluded_messages = [r'{}'.format(msg) for msg in item["excluded_messages"]]
137+
excluded_messages = [r'{}'.format(msg) for msg in item.get("excluded_messages", [])]
138138
self.exclude_filters[event_name] = excluded_messages
139139

140140
# Since `collect_per_instance_filters` have the same structure as `metric_filters` we use the same parser

vsphere/datadog_checks/vsphere/data/conf.yaml.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ instances:
271271
## @param include_events - list of mappings - optional
272272
## The events that should be collected by the vSphere integration.
273273
##
274-
## The "event" specifies the event type you want to include, and the "excluded_messages" is a list of
275-
## messages of that event type you do not want to collect. For example, if the key
274+
## The "event" specifies the event type you want to include, and optionally, the "excluded_messages" is
275+
## a list of messages of that event type you do not want to collect. For example, if the key
276276
## is 'AlarmStatusChangedEvent' and the values for this key are 'Gray to Green' and 'Green to Gray',
277277
## then all events named 'AlarmStatusChangedEvent' that don't have the message 'Gray to Green'
278278
## and 'Green to Gray' will be included.

vsphere/tests/test_event.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,30 @@ def test_include_events_ok(aggregator, realtime_instance, dd_run_check, mock_api
368368
assert aggregator.events[0]['msg_title'] == "[Triggered] alarm1 on VM vm1 is now red"
369369

370370

371+
@pytest.mark.usefixtures('mock_type', 'mock_threadpool', 'mock_rest_api')
372+
def test_include_events_no_excluded_message(aggregator, realtime_instance, dd_run_check, mock_api):
373+
realtime_instance['include_events'] = [{"event": "AlarmStatusChangedEvent"}]
374+
check = VSphereCheck('vsphere', {}, [realtime_instance])
375+
event1 = vim.event.AlarmStatusChangedEvent()
376+
event1.createdTime = dt.datetime.now()
377+
event1.entity = vim.event.ManagedEntityEventArgument()
378+
event1.entity.entity = vim.VirtualMachine(moId="vm1")
379+
event1.entity.name = "vm1"
380+
event1.alarm = vim.event.AlarmEventArgument()
381+
event1.alarm.name = "alarm1"
382+
setattr(event1, 'from', 'green')
383+
event1.to = 'red'
384+
event1.datacenter = vim.event.DatacenterEventArgument()
385+
event1.datacenter.name = "dc1"
386+
event1.fullFormattedMessage = "Green to Red"
387+
mock_api.side_effect = mock_api_with_events([event1])
388+
389+
dd_run_check(check)
390+
391+
assert len(aggregator.events) == 1
392+
assert aggregator.events[0]['msg_title'] == "[Triggered] alarm1 on VM vm1 is now red"
393+
394+
371395
@pytest.mark.usefixtures('mock_type', 'mock_threadpool', 'mock_rest_api')
372396
def test_include_events_filtered(aggregator, realtime_instance, dd_run_check, mock_api):
373397
realtime_instance['include_events'] = [

0 commit comments

Comments
 (0)