Skip to content

Commit

Permalink
[NDM] [Cisco ACI] Fix APIC device status (DataDog#19204)
Browse files Browse the repository at this point in the history
* Fix APIC status check

* Add changelog
  • Loading branch information
zoedt authored Dec 10, 2024
1 parent 53dc9f7 commit 2d857d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions cisco_aci/changelog.d/19204.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[NDM] [Cisco ACI] Fix APIC device status
33 changes: 18 additions & 15 deletions cisco_aci/datadog_checks/cisco_aci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class NodeAttributes(BaseModel):
address: Optional[str] = None
ad_st: Optional[str] = Field(default=None, alias="adSt")
fabric_st: Optional[str] = Field(default=None, alias="fabricSt")
role: Optional[str] = None
dn: Optional[str] = None
Expand All @@ -34,6 +35,22 @@ def device_type(self) -> str:
return 'switch'
return 'other'

@computed_field
@property
def status(self) -> int:
if self.role == 'controller':
return 1 if self.ad_st == 'on' else 2
mapping = {
'active': 1,
'inactive': 2,
'disabled': 2,
'discovering': 2,
'undiscovered': 2,
'unsupported': 2,
'unknown': 2,
}
return mapping.get(self.fabric_st, 2)


class Node(BaseModel):
attributes: NodeAttributes
Expand Down Expand Up @@ -161,8 +178,8 @@ class DeviceMetadata(BaseModel):
tags: list = Field(default_factory=list)
name: Optional[str] = Field(default=None)
ip_address: Optional[str] = Field(default=None)
status: Optional[int] = Field(default=None)
model: Optional[str] = Field(default=None)
fabric_st: Optional[str] = Field(default=None, exclude=True)
vendor: Optional[str] = Field(default=None)
version: Optional[str] = Field(default=None)
serial_number: Optional[str] = Field(default=None)
Expand All @@ -172,20 +189,6 @@ class DeviceMetadata(BaseModel):
# non-exported fields
pod_node_id: Optional[str] = Field(default=None, exclude=True)

@computed_field
@property
def status(self) -> int:
mapping = {
'active': 1,
'inactive': 2,
'disabled': 2,
'discovering': 2,
'undiscovered': 2,
'unsupported': 2,
'unknown': 2,
}
return mapping.get(self.fabric_st, 2)


class DeviceMetadataList(BaseModel):
device_metadata: list = Field(default_factory=list)
Expand Down
2 changes: 1 addition & 1 deletion cisco_aci/datadog_checks/cisco_aci/ndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def create_node_metadata(node_attrs, tags, namespace):
tags=device_tags + tags,
name=hostname,
ip_address=node.attributes.address,
status=node.attributes.status,
model=node.attributes.model,
fabric_st=node.attributes.fabric_st,
vendor=VENDOR_CISCO,
version=node.attributes.version,
serial_number=node.attributes.serial,
Expand Down
6 changes: 1 addition & 5 deletions cisco_aci/tests/fixtures/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
],
'ip_address': '10.0.200.0',
'model': 'N9K-C93180YC-FX',
'fabric_st': 'active',
'name': 'leaf101',
'serial_number': 'FDO20440TS1',
'status': 1,
Expand Down Expand Up @@ -62,7 +61,6 @@
],
'ip_address': '10.0.200.1',
'model': 'N9K-C93180YC-FX',
'fabric_st': 'active',
'name': 'leaf102',
'serial_number': 'FDO20510HCA',
'status': 1,
Expand Down Expand Up @@ -93,10 +91,9 @@
],
'ip_address': '10.0.200.4',
'model': 'APIC-SERVER-M1',
'fabric_st': 'unknown',
'name': 'apic1',
'serial_number': 'FCH1928V0SL',
'status': 2,
'status': 1,
'vendor': 'cisco',
'version': 'A',
},
Expand Down Expand Up @@ -125,7 +122,6 @@
],
'ip_address': '10.0.200.5',
'model': 'N9K-C9336PQ',
'fabric_st': 'active',
'name': 'spine201',
'serial_number': 'SAL2014N5U4',
'status': 1,
Expand Down

0 comments on commit 2d857d3

Please sign in to comment.