Skip to content

Commit

Permalink
Merge pull request #946 from netenglabs/fix-lldp-cisco
Browse files Browse the repository at this point in the history
Fix lldp cisco
  • Loading branch information
ddutt authored May 23, 2024
2 parents 7499645 + 9484449 commit 3a96659
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
20 changes: 12 additions & 8 deletions suzieq/config/lldp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,28 @@ apply:

- version: all
command:
- command: show cdp neighbors | json native
normalize: 'TABLE_cdp_neighbor_brief_info/ROW_cdp_neighbor_brief_info/*?/[
- command: show cdp neighbors detail | json native
normalize: 'TABLE_cdp_neighbor_detail_info/ROW_cdp_neighbor_detail_info/*?/[
"interface: ifname?|",
"intf_id: ifname?|ifname",
"device_id: peerHostname?|",
"platform_id: description?|",
"sysname: peerHostname?|",
"platform_id: peerPlatform?|",
"port_id: peerIfname",
"v4addr: mgmtIP?|",
"version: description?|",
"protocol: protocol?|cdp",
]'

- command: show lldp neighbors | json native
normalize: 'TABLE_nbor/ROW_nbor/*?/[
"chassis_id: peerHostname?|",
- command: show lldp neighbors detail | json native
normalize: 'TABLE_nbor_detail/ROW_nbor_detail/*?/[
"sys_name: peerHostname?|",
"chassis_type: _chassisType",
"l_port_id: ifname?|",
"port_type: subtype?|",
"port_id: peerIfname?|",
"mgmt_addr: mgmtIP?|"
"mgmt_addr: mgmtIP?|",
"sys_desc: description?|",
"enabled_capability: _capabilities?|",
]'

panos:
Expand Down
43 changes: 36 additions & 7 deletions suzieq/poller/worker/services/lldp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from typing import Dict, List

import numpy as np

Expand Down Expand Up @@ -65,8 +66,8 @@ def _common_cleaner(self, entry):

def _clean_nxos_data(self, processed_data, _):

drop_indices = []
entries = {}
drop_indices: List[int] = []
entries: Dict[str, int] = {}

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

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

if entry['ifname'] in entries:
# Handle the case where both LLDP and CDP entries are present.
# Ensure we copy the relvant fields from one into the other.
# key is computed to handle p2mp ports.
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
f'{entry.get("peerIfname")}')
if key in entries:
old_entry = processed_data[entries[key]]

# Description is sometimes filled in with CDP, but not LLDP
if not entry.get('description', ''):
old_entry = processed_data[entries[entry['ifname']]]
entry['description'] = old_entry.get('description', '')
entry['subtype'] = old_entry.get('subtype', '')
drop_indices.append(entries[entry['ifname']])
if not entry.get('peerPlatform', ''):
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
drop_indices.append(entries[key])
else:
entries[entry['ifname']] = i
entries[key] = i

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

def _clean_iosxe_data(self, processed_data, _):

drop_indices = []
drop_indices: List[int] = []
entries: Dict[str, int] = {}

for i, entry in enumerate(processed_data):
entry['peerHostname'] = re.sub(r'\(.*\)', '',
entry['peerHostname'])
Expand All @@ -223,6 +234,24 @@ def _clean_iosxe_data(self, processed_data, _):
entry[field] = expand_ios_ifname(entry[field])
if ' ' in entry.get(field, ''):
entry[field] = entry[field].replace(' ', '')

# Handle the case where both LLDP and CDP entries are present.
# Ensure we copy the relvant fields from one into the other.
# key is computed to handle p2mp ports.
key = (f'{entry.get("ifname")}-{entry.get("peerHostname")}-'
f'{entry.get("peerIfname")}')
if key in entries:
old_entry = processed_data[entries[key]]
# Description is sometimes filled in with CDP, but not LLDP
if not entry.get('description', ''):
entry['description'] = old_entry.get('description', '')
entry['subtype'] = old_entry.get('subtype', '')
if not entry.get('peerPlatform', ''):
entry['peerPlatform'] = old_entry.get('peerPlatform', '')
drop_indices.append(entries[key])
else:
entries[key] = i

self._common_cleaner(entry)

processed_data = np.delete(processed_data, drop_indices).tolist()
Expand Down

0 comments on commit 3a96659

Please sign in to comment.