Skip to content

Commit

Permalink
[NDM] [Cisco ACI] Use actual int for interface index (#18414)
Browse files Browse the repository at this point in the history
* Use actual int for interface index

* Changelog

* Update cisco_aci/datadog_checks/cisco_aci/models.py

Co-authored-by: dkirov-dd <166512750+dkirov-dd@users.noreply.github.com>

---------

Co-authored-by: Jim Wilson <86026167+jmw51798@users.noreply.github.com>
Co-authored-by: dkirov-dd <166512750+dkirov-dd@users.noreply.github.com>
(cherry picked from commit 6915c80)
  • Loading branch information
zoedt authored and github-actions[bot] committed Aug 28, 2024
1 parent 698c1eb commit 9e962ad
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 230 deletions.
1 change: 1 addition & 0 deletions cisco_aci/changelog.d/18414.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[NDM] [Cisco ACI] Use actual int for interface index
14 changes: 13 additions & 1 deletion cisco_aci/datadog_checks/cisco_aci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)

import re

import six

if six.PY3:
Expand Down Expand Up @@ -123,7 +125,7 @@ class Status(StrEnum):
class InterfaceMetadata(BaseModel):
device_id: Optional[str] = Field(default=None)
id_tags: list = Field(default_factory=list)
index: Optional[str] = Field(default=None)
index: Optional[int] = Field(default=None)
name: Optional[str] = Field(default=None)
description: Optional[str] = Field(default=None)
mac_address: Optional[str] = Field(default=None)
Expand Down Expand Up @@ -151,6 +153,16 @@ def parse_oper_status(cls, oper_status: OperStatus | None) -> OperStatus | None:
return OperStatus.UP
return OperStatus.DOWN

@field_validator("index", mode="before")
@classmethod
def parse_index(cls, index: str | int | None) -> int | None:
if type(index) == str:
split = re.split('eth|/', index)
return int(split[-1])
if type(index) == int:
return index
return None

@computed_field
@property
def status(self) -> Status:
Expand Down
Loading

0 comments on commit 9e962ad

Please sign in to comment.