Skip to content

Commit 61aaddd

Browse files
authored
[PLINT-363] Add additional event tags for non-host resources (#17403)
* Add additional event tags for non host resources * Add changelog * Fix * fix changelog
1 parent eb87212 commit 61aaddd

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

vsphere/changelog.d/17403.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add additional tags on events for non-host resources.

vsphere/datadog_checks/vsphere/event.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from datadog_checks.base import ensure_unicode
1313

14-
from .constants import MOR_TYPE_AS_STRING, SOURCE_TYPE
14+
from .constants import DEFAULT_EVENT_RESOURCES, MOR_TYPE_AS_STRING, SOURCE_TYPE
1515

1616
EXCLUDE_FILTERS = {
1717
'AlarmStatusChangedEvent': [r'Gray to Green', r'Green to Gray'],
@@ -193,6 +193,16 @@ def get_agg_key(alarm_event):
193193
)
194194
if host_name is not None:
195195
self.payload['host'] = host_name
196+
197+
# VMs and hosts submit these as host tags
198+
if self.host_type.lower() not in DEFAULT_EVENT_RESOURCES:
199+
self.payload['tags'].extend(
200+
[
201+
'vsphere_type:{}'.format(self.host_type),
202+
'vsphere_resource:{}'.format(entity_name),
203+
]
204+
)
205+
196206
return self.payload
197207

198208
def transform_vmmessageevent(self):

vsphere/tests/test_event.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,14 @@ def test_events_collection(aggregator, realtime_instance):
126126

127127
check.api.mock_events = [event2, event3, event3, event4]
128128
check.check(None)
129-
for from_status, to_status, count in [('yellow', 'red', 1), ('red', 'red', 2), ('red', 'green', 1)]:
129+
for from_status, to_status, count, additional_tags in [
130+
('yellow', 'red', 1, []),
131+
('red', 'red', 2, []),
132+
('red', 'green', 1, ['vsphere_type:cluster', 'vsphere_resource:c1']),
133+
]:
130134
aggregator.assert_event(
131135
"vCenter monitor status changed on this alarm, it was {} and it's now {}.".format(from_status, to_status),
132-
tags=['vcenter_server:FAKE'],
136+
tags=additional_tags + ['vcenter_server:FAKE'],
133137
count=count,
134138
)
135139
assert len(aggregator.events) == 4
@@ -142,10 +146,12 @@ def test_events_collection(aggregator, realtime_instance):
142146

143147
check.api.mock_events = [event2, event3, event3, event4]
144148
check.check(None)
145-
for from_status, to_status, count in [('red', 'green', 1)]:
149+
for from_status, to_status, count, additional_tags in [
150+
('red', 'green', 1, ['vsphere_type:cluster', 'vsphere_resource:c1'])
151+
]:
146152
aggregator.assert_event(
147153
"vCenter monitor status changed on this alarm, it was {} and it's now {}.".format(from_status, to_status),
148-
tags=['vcenter_server:FAKE'],
154+
tags=additional_tags + ['vcenter_server:FAKE'],
149155
count=count,
150156
)
151157
assert len(aggregator.events) == 1

0 commit comments

Comments
 (0)