Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nxos ssh get interfaces counters #1287

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions napalm/nxos_ssh/nxos_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,3 +1641,100 @@ def get_optics(self):
optics_detail[port] = port_detail

return optics_detail

def get_interfaces_counters(self):
"""
Return interface counters and errors.

'tx_errors': int,
'rx_errors': int,
'tx_discards': int,
'rx_discards': int,
'tx_octets': int,
'rx_octets': int,
'tx_unicast_packets': int,
'rx_unicast_packets': int,
'tx_multicast_packets': int,
'rx_multicast_packets': int,
'tx_broadcast_packets': int,
'rx_broadcast_packets': int,
"""
if_mapping = {
"eth": {
"regexp": re.compile("^(Ether|port-channel).*"),
"mapping": {
"tx_errors": "eth_outerr",
"rx_errors": "eth_inerr",
"tx_discards": "eth_outdiscard",
"rx_discards": "eth_indiscard",
"tx_octets": "eth_outbytes",
"rx_octets": "eth_inbytes",
"tx_unicast_packets": "eth_outucast",
"rx_unicast_packets": "eth_inucast",
"tx_multicast_packets": "eth_outmcast",
"rx_multicast_packets": "eth_inmcast",
"tx_broadcast_packets": "eth_outbcast",
"rx_broadcast_packets": "eth_inbcast",
},
},
"mgmt": {
"regexp": re.compile("mgm.*"),
"mapping": {
"tx_errors": None,
"rx_errors": None,
"tx_discards": None,
"rx_discards": None,
"tx_octets": "mgmt_out_bytes",
"rx_octets": "mgmt_in_bytes",
"tx_unicast_packets": None,
"rx_unicast_packets": None,
"tx_multicast_packets": "mgmt_out_mcast",
"rx_multicast_packets": "mgmt_in_mcast",
"tx_broadcast_packets": None,
"rx_broadcast_packets": None,
},
},
}
command = "show interface counters detailed | json"
# To retrieve discards
command_interface = "show interface | json"
counters_table_raw = self._get_command_table(
command, "TABLE_interface", "ROW_interface"
)
counters_interface_table_raw = self._get_command_table(
command_interface, "TABLE_interface", "ROW_interface"
)
all_stats_d = {}
# Start with show interface as all interfaces
# Are surely listed
for row in counters_interface_table_raw:
if_counter = {}
# loop through regexp to find mapping
for if_v in if_mapping:
my_re = if_mapping[if_v]["regexp"]
re_match = my_re.match(row["interface"])
if re_match:
interface = re_match.group()
map_d = if_mapping[if_v]["mapping"]
for k, v in map_d.items():
if_counter[k] = int(row[v]) if v in row else 0
all_stats_d[interface] = if_counter
break
print(all_stats_d)

for row in counters_table_raw:
if_counter = {}
# loop through regexp to find mapping
for if_v in if_mapping:
my_re = if_mapping[if_v]["regexp"]
re_match = my_re.match(row["interface"])
if re_match:
interface = re_match.group()
map_d = if_mapping[if_v]["mapping"]
for k, v in map_d.items():
if v in row:
if_counter[k] = int(row[v])
all_stats_d[interface].update(if_counter)
break

return all_stats_d
Loading