Skip to content

Commit 70da53f

Browse files
authored
Merge branch 'develop' into feature/cisco_ios_get_probes_results
2 parents b570363 + 2ac2b22 commit 70da53f

File tree

5 files changed

+6016
-1
lines changed

5 files changed

+6016
-1
lines changed

napalm/nxos_ssh/nxos_ssh.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,3 +1641,100 @@ def get_optics(self):
16411641
optics_detail[port] = port_detail
16421642

16431643
return optics_detail
1644+
1645+
def get_interfaces_counters(self):
1646+
"""
1647+
Return interface counters and errors.
1648+
1649+
'tx_errors': int,
1650+
'rx_errors': int,
1651+
'tx_discards': int,
1652+
'rx_discards': int,
1653+
'tx_octets': int,
1654+
'rx_octets': int,
1655+
'tx_unicast_packets': int,
1656+
'rx_unicast_packets': int,
1657+
'tx_multicast_packets': int,
1658+
'rx_multicast_packets': int,
1659+
'tx_broadcast_packets': int,
1660+
'rx_broadcast_packets': int,
1661+
"""
1662+
if_mapping = {
1663+
"eth": {
1664+
"regexp": re.compile("^(Ether|port-channel).*"),
1665+
"mapping": {
1666+
"tx_errors": "eth_outerr",
1667+
"rx_errors": "eth_inerr",
1668+
"tx_discards": "eth_outdiscard",
1669+
"rx_discards": "eth_indiscard",
1670+
"tx_octets": "eth_outbytes",
1671+
"rx_octets": "eth_inbytes",
1672+
"tx_unicast_packets": "eth_outucast",
1673+
"rx_unicast_packets": "eth_inucast",
1674+
"tx_multicast_packets": "eth_outmcast",
1675+
"rx_multicast_packets": "eth_inmcast",
1676+
"tx_broadcast_packets": "eth_outbcast",
1677+
"rx_broadcast_packets": "eth_inbcast",
1678+
},
1679+
},
1680+
"mgmt": {
1681+
"regexp": re.compile("mgm.*"),
1682+
"mapping": {
1683+
"tx_errors": None,
1684+
"rx_errors": None,
1685+
"tx_discards": None,
1686+
"rx_discards": None,
1687+
"tx_octets": "mgmt_out_bytes",
1688+
"rx_octets": "mgmt_in_bytes",
1689+
"tx_unicast_packets": None,
1690+
"rx_unicast_packets": None,
1691+
"tx_multicast_packets": "mgmt_out_mcast",
1692+
"rx_multicast_packets": "mgmt_in_mcast",
1693+
"tx_broadcast_packets": None,
1694+
"rx_broadcast_packets": None,
1695+
},
1696+
},
1697+
}
1698+
command = "show interface counters detailed | json"
1699+
# To retrieve discards
1700+
command_interface = "show interface | json"
1701+
counters_table_raw = self._get_command_table(
1702+
command, "TABLE_interface", "ROW_interface"
1703+
)
1704+
counters_interface_table_raw = self._get_command_table(
1705+
command_interface, "TABLE_interface", "ROW_interface"
1706+
)
1707+
all_stats_d = {}
1708+
# Start with show interface as all interfaces
1709+
# Are surely listed
1710+
for row in counters_interface_table_raw:
1711+
if_counter = {}
1712+
# loop through regexp to find mapping
1713+
for if_v in if_mapping:
1714+
my_re = if_mapping[if_v]["regexp"]
1715+
re_match = my_re.match(row["interface"])
1716+
if re_match:
1717+
interface = re_match.group()
1718+
map_d = if_mapping[if_v]["mapping"]
1719+
for k, v in map_d.items():
1720+
if_counter[k] = int(row[v]) if v in row else 0
1721+
all_stats_d[interface] = if_counter
1722+
break
1723+
print(all_stats_d)
1724+
1725+
for row in counters_table_raw:
1726+
if_counter = {}
1727+
# loop through regexp to find mapping
1728+
for if_v in if_mapping:
1729+
my_re = if_mapping[if_v]["regexp"]
1730+
re_match = my_re.match(row["interface"])
1731+
if re_match:
1732+
interface = re_match.group()
1733+
map_d = if_mapping[if_v]["mapping"]
1734+
for k, v in map_d.items():
1735+
if v in row:
1736+
if_counter[k] = int(row[v])
1737+
all_stats_d[interface].update(if_counter)
1738+
break
1739+
1740+
return all_stats_d

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ pytest-json==0.4.0
88
pytest-pythonpath==0.7.3
99
pylama==7.7.1
1010
mock==4.0.2
11-
tox==3.19.0
11+
tox==3.20.0

0 commit comments

Comments
 (0)