Skip to content

Commit 5ef8f98

Browse files
authored
[NDINT-387] Get health score from healthInst if fvOverallHealth isn't present (DataDog#21988)
* [NDINT-387] Get health score from healthInst if fvOverallHealth isn't present. * Changelog entry.
1 parent d4c02f3 commit 5ef8f98

9 files changed

Lines changed: 54214 additions & 5 deletions

File tree

cisco_aci/changelog.d/21988.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Get health score from healthInst if fvOverallHealth isn't enabled.

cisco_aci/datadog_checks/cisco_aci/aci_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363

6464
def make_tenant_metrics():
6565
metrics = {
66+
"healthInst": {"cur": "{}.health"},
6667
"fvOverallHealth": {"healthAvg": "{}.overall_health", "healthLast": "{}.health"},
6768
"fvFltCounter": {"warncountAvg": "{}.fault_counter"},
6869
}

cisco_aci/datadog_checks/cisco_aci/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def get_eth_list_for_epg(self, tenant, app, epg):
219219
return self._parse_response(response)
220220

221221
def get_tenant_stats(self, tenant):
222-
path = "/api/mo/uni/tn-{}.json?rsp-subtree-include=stats,no-scoped".format(tenant)
222+
path = "/api/mo/uni/tn-{}.json?rsp-subtree-include=stats,health,no-scoped".format(tenant)
223223
response = self.make_request(path)
224224
# return only the list of stats
225225
return self._parse_response(response)

cisco_aci/datadog_checks/cisco_aci/tenant.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def _submit_ten_data(self, tenant):
8585
pass
8686

8787
def submit_raw_obj(self, raw_stats, tags, obj_type):
88+
got_health = False
8889
for s in raw_stats:
8990
name = list(s.keys())[0]
9091
# we only want to collect the 15 minutes metrics.
@@ -110,5 +111,25 @@ def submit_raw_obj(self, raw_stats, tags, obj_type):
110111
json_attrs = s.get(name, {}).get("attributes", {})
111112
if mval and helpers.check_metric_can_be_zero(cisco_metric, mval, json_attrs):
112113
metrics[dd_metric] = mval
113-
114+
if 'fvOverallHealth' in name:
115+
got_health = True
114116
self.submit_metrics(metrics, tags, instance=self.instance)
117+
118+
if got_health:
119+
return
120+
self.log.debug("No fvOverallHealth reported, looking for healthInst instead")
121+
health_insts = [s for s in raw_stats if list(s.keys())[0] == "healthInst"]
122+
if not health_insts:
123+
self.log.debug("No healthInst reported")
124+
return
125+
s = health_insts[0]
126+
self.log.debug("submitting metrics for: %s", 'healthInst')
127+
metrics = {}
128+
129+
ms = self.tenant_metrics.get(obj_type, {}).get('healthInst', {})
130+
for cisco_metric, dd_metric in ms.items():
131+
mval = s.get('healthInst', {}).get("attributes", {}).get(cisco_metric)
132+
json_attrs = s.get('healthInst', {}).get("attributes", {})
133+
if mval and helpers.check_metric_can_be_zero(cisco_metric, mval, json_attrs):
134+
metrics[dd_metric] = mval
135+
self.submit_metrics(metrics, tags, instance=self.instance)

cisco_aci/tests/common.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@
172172
# 643d217904f09445fbc9f7b43cd131f0 - Api.get_fabric_pods
173173
'_api_mo_uni_tn_DataDog_json_query_target_subtree_target_subtree_class_fvAp',
174174
# 4efe80304d50330f5ed0f79252ef0a84 - Api.get_apps
175-
'_api_mo_uni_tn_DataDog_json_rsp_subtree_include_stats_no_scoped',
176-
# c8e9a0dbceac67fb1149684f7fc7772c - Api.get_tenant_stats
175+
'_api_mo_uni_tn_DataDog_json_rsp_subtree_include_stats_health_no_scoped',
176+
# 07f9ef7474c39eef33e9ddfd269d54fb - Api.get_tenant_stats
177+
'_api_mo_uni_tn_DataDogAlt_json_rsp_subtree_include_stats_health_no_scoped',
178+
# cd84d80314a78b27c72f287322f30b68 - Api.get_tenant_stats
177179
'_api_node_class_lldpAdjEp_json',
178180
# f3713df3a586908a3a11f4c356153519 - Api.get_lldp_adj_eps
179181
'_api_node_class_cdpAdjEp_json',
@@ -228,6 +230,9 @@ def make_request(self, path):
228230
mock_path = mock_path.replace('[', '_')
229231
mock_path = mock_path.replace(']', '_')
230232
mock_path = mock_path.replace('|', '_')
233+
if mock_path not in FIXTURE_LIST_FILE_MAP:
234+
log.debug("Skipping %s - no fixture file found", path)
235+
return {"imdata": []}
231236
mock_path = FIXTURE_LIST_FILE_MAP[mock_path]
232237
for p in self.fixture_dirs:
233238
path = os.path.join(p, mock_path)

0 commit comments

Comments
 (0)