Skip to content

Commit d618058

Browse files
committed
IOS MAC Parser: Handle versions which start with * in output
Signed-off-by: Dinesh Dutt <[email protected]>
1 parent 38400fd commit d618058

File tree

2 files changed

+24
-43
lines changed

2 files changed

+24
-43
lines changed

suzieq/config/textfsm_templates/iosxe_show_mac.tfsm

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,21 @@ Value Required macaddr (\S+)
33
Value Required flags (\w+)
44
Value oif (\S+)
55
Value protocol (\S+)
6+
Value _learn (\w+)
7+
Value age (\d+|-)
8+
Value List _ports (\S+)
69

710
Start
11+
^\* -> WithStar
812
^\s+vlan.*protocol.* -> WithProtocol
913
^\s*${vlan}\s+${macaddr}\s+${flags}\s+${oif}.*$$ -> Record
1014

1115
WithProtocol
1216
^\s*${vlan}\s+${macaddr}\s+${flags}\s+${protocol}\s+${oif}.*$$ -> Record
1317
^Multicast\s+Entries -> Start
1418

15-
# Mac Address Table
16-
#-------------------------------------------
17-
#
18-
#Vlan Mac Address Type Ports
19-
#---- ----------- -------- -----
20-
# All 0100.0ccc.cccc STATIC CPU
21-
# All 0100.0ccc.cccd STATIC CPU
22-
# All 0180.c200.0000 STATIC CPU
23-
# All 0180.c200.0001 STATIC CPU
24-
# All 0180.c200.0002 STATIC CPU
25-
# All 0180.c200.0003 STATIC CPU
26-
# All 0180.c200.0004 STATIC CPU
27-
# All 0180.c200.0005 STATIC CPU
28-
# All 0180.c200.0006 STATIC CPU
29-
# All 0180.c200.0007 STATIC CPU
30-
# All 0180.c200.0008 STATIC CPU
31-
# All 0180.c200.0009 STATIC CPU
32-
# All 0180.c200.000a STATIC CPU
33-
# All 0180.c200.000b STATIC CPU
34-
# All 0180.c200.000c STATIC CPU
35-
# All 0180.c200.000d STATIC CPU
36-
# All 0180.c200.000e STATIC CPU
37-
# All 0180.c200.000f STATIC CPU
38-
# All 0180.c200.0010 STATIC CPU
39-
# All 0180.c200.0021 STATIC CPU
40-
# All ffff.ffff.ffff STATIC CPU
41-
# 1 780c.f0e1.1dc3 STATIC Vl1
42-
# 51 0000.1111.2222 STATIC Vl51
43-
# 51 780c.f0e1.1dc6 STATIC Vl51
44-
#1021 0000.0c9f.f45c STATIC Vl1021
45-
#1021 0002.02cc.0002 STATIC Gi6/0/2
46-
#1021 0002.02cc.0003 STATIC Gi6/0/3
47-
#1021 0002.02cc.0004 STATIC Gi6/0/4
48-
#1021 0002.02cc.0005 STATIC Gi6/0/5
49-
#1021 0002.02cc.0006 STATIC Gi6/0/6
50-
#1021 0002.02cc.0007 STATIC Gi6/0/7
51-
#1021 0002.02cc.0008 STATIC Gi6/0/8
52-
#1021 0002.02cc.0009 STATIC Gi6/0/9
53-
#1021 0002.02cc.000a STATIC Gi6/0/10
54-
#
19+
WithStar
20+
^\* -> Continue.Record
21+
^\*\s+${vlan}\s+${macaddr}\s+${flags}\s+${_learn}\s+${age}\s+${_ports}
22+
^\s+${_ports}
23+

suzieq/poller/worker/services/macs.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,26 @@ def _clean_iosxe_data(self, processed_data, _):
160160
for entry in processed_data:
161161
entry['macaddr'] = convert_macaddr_format_to_colon(
162162
entry.get('macaddr', '0000.0000.0000'))
163+
oiflist = []
163164
oifs = ''
164-
for oif in entry.get('oif', '').split(','):
165-
# Handle multicast entries
165+
oif = entry.get('oif', '').strip()
166+
if oif:
167+
oiflist = oif.split(',')
168+
if not oiflist:
169+
# Some versions of IOS/XE have a different output
170+
# format and we capture that in a different var
171+
oif = entry.get('_ports', '')
172+
if oif:
173+
for ele in oif:
174+
oiflist.extend(ele.split(','))
175+
for oif in oiflist:
176+
# Handles multicast entries
166177
oifs += f'{expand_ios_ifname(oif)} '
167178
if oifs:
168179
entry['oif'] = oifs.strip()
169180
else:
170-
entry['oif'] = expand_ios_ifname(entry['oif'])
181+
entry['oif'] = ''
182+
171183
entry['remoteVtepIp'] = ''
172184
if entry.get('vlan', ' ').strip() == "All":
173185
entry['vlan'] = 0

0 commit comments

Comments
 (0)