Skip to content

Commit 3a96659

Browse files
authored
Merge pull request #946 from netenglabs/fix-lldp-cisco
Fix lldp cisco
2 parents 7499645 + 9484449 commit 3a96659

File tree

2 files changed

+48
-15
lines changed

2 files changed

+48
-15
lines changed

suzieq/config/lldp.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,28 @@ apply:
118118

119119
- version: all
120120
command:
121-
- command: show cdp neighbors | json native
122-
normalize: 'TABLE_cdp_neighbor_brief_info/ROW_cdp_neighbor_brief_info/*?/[
121+
- command: show cdp neighbors detail | json native
122+
normalize: 'TABLE_cdp_neighbor_detail_info/ROW_cdp_neighbor_detail_info/*?/[
123123
"interface: ifname?|",
124124
"intf_id: ifname?|ifname",
125-
"device_id: peerHostname?|",
126-
"platform_id: description?|",
125+
"sysname: peerHostname?|",
126+
"platform_id: peerPlatform?|",
127127
"port_id: peerIfname",
128+
"v4addr: mgmtIP?|",
129+
"version: description?|",
128130
"protocol: protocol?|cdp",
129131
]'
130132

131-
- command: show lldp neighbors | json native
132-
normalize: 'TABLE_nbor/ROW_nbor/*?/[
133-
"chassis_id: peerHostname?|",
133+
- command: show lldp neighbors detail | json native
134+
normalize: 'TABLE_nbor_detail/ROW_nbor_detail/*?/[
135+
"sys_name: peerHostname?|",
134136
"chassis_type: _chassisType",
135137
"l_port_id: ifname?|",
136138
"port_type: subtype?|",
137139
"port_id: peerIfname?|",
138-
"mgmt_addr: mgmtIP?|"
140+
"mgmt_addr: mgmtIP?|",
141+
"sys_desc: description?|",
142+
"enabled_capability: _capabilities?|",
139143
]'
140144

141145
panos:

suzieq/poller/worker/services/lldp.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from typing import Dict, List
23

34
import numpy as np
45

@@ -65,8 +66,8 @@ def _common_cleaner(self, entry):
6566

6667
def _clean_nxos_data(self, processed_data, _):
6768

68-
drop_indices = []
69-
entries = {}
69+
drop_indices: List[int] = []
70+
entries: Dict[str, int] = {}
7071

7172
for i, entry in enumerate(processed_data):
7273
entry['peerHostname'] = re.sub(r'\(.*\)', '',
@@ -88,15 +89,23 @@ def _clean_nxos_data(self, processed_data, _):
8889

8990
entry['ifname'] = expand_nxos_ifname(entry['ifname'])
9091

91-
if entry['ifname'] in entries:
92+
# Handle the case where both LLDP and CDP entries are present.
93+
# Ensure we copy the relvant fields from one into the other.
94+
# key is computed to handle p2mp ports.
95+
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
96+
f'{entry.get("peerIfname")}')
97+
if key in entries:
98+
old_entry = processed_data[entries[key]]
99+
92100
# Description is sometimes filled in with CDP, but not LLDP
93101
if not entry.get('description', ''):
94-
old_entry = processed_data[entries[entry['ifname']]]
95102
entry['description'] = old_entry.get('description', '')
96103
entry['subtype'] = old_entry.get('subtype', '')
97-
drop_indices.append(entries[entry['ifname']])
104+
if not entry.get('peerPlatform', ''):
105+
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
106+
drop_indices.append(entries[key])
98107
else:
99-
entries[entry['ifname']] = i
108+
entries[key] = i
100109

101110
if entry.get('protocol', '') == 'cdp':
102111
entry['subtype'] = 'interface name'
@@ -203,7 +212,9 @@ def _clean_iosxr_data(self, processed_data, _):
203212

204213
def _clean_iosxe_data(self, processed_data, _):
205214

206-
drop_indices = []
215+
drop_indices: List[int] = []
216+
entries: Dict[str, int] = {}
217+
207218
for i, entry in enumerate(processed_data):
208219
entry['peerHostname'] = re.sub(r'\(.*\)', '',
209220
entry['peerHostname'])
@@ -223,6 +234,24 @@ def _clean_iosxe_data(self, processed_data, _):
223234
entry[field] = expand_ios_ifname(entry[field])
224235
if ' ' in entry.get(field, ''):
225236
entry[field] = entry[field].replace(' ', '')
237+
238+
# Handle the case where both LLDP and CDP entries are present.
239+
# Ensure we copy the relvant fields from one into the other.
240+
# key is computed to handle p2mp ports.
241+
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
242+
f'{entry.get("peerIfname")}')
243+
if key in entries:
244+
old_entry = processed_data[entries[key]]
245+
# Description is sometimes filled in with CDP, but not LLDP
246+
if not entry.get('description', ''):
247+
entry['description'] = old_entry.get('description', '')
248+
entry['subtype'] = old_entry.get('subtype', '')
249+
if not entry.get('peerPlatform', ''):
250+
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
251+
drop_indices.append(entries[key])
252+
else:
253+
entries[key] = i
254+
226255
self._common_cleaner(entry)
227256

228257
processed_data = np.delete(processed_data, drop_indices).tolist()

0 commit comments

Comments
 (0)