2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-29 13:00:03 +00:00

Fix unprintable characters in some chassisid

Some switches send raw octets back, some printable.  Try to normalize
when unprintable chassis id are detected.  This is not 100%, if the hex
would be all between 20 and 80 throughout the string, then this will
fail to do the right thing.

Hopefully, the amount of times when lldp partners disagree on how to
implement LLDP-MIB will be limited.  Currently it is known than Lenovo
and Juniper switches disagree, and both of those have what would
be unprintable values in the mfg portion of the chassis id.
This commit is contained in:
Jarrod Johnson 2018-05-21 15:53:12 -04:00
parent fbbb5d048f
commit a4fed0601c

View File

@ -151,6 +151,9 @@ def _extract_extended_desc(info, source, integritychecked):
info['peerdescription'] = source
def sanitize(val):
# This is pretty much the same approach net-snmp takes.
# if the string is printable as-is, then just give it as-is
# if the string has non-printable, then hexify it
val = str(val)
for x in val.strip('\x00'):
if ord(x) < 32 or ord(x) > 128:
@ -161,7 +164,7 @@ def sanitize(val):
def _init_lldp(data, iname, idx, idxtoportid, switch):
if iname not in data:
data[iname] = {'port': iname, 'portid': str(idxtoportid[idx]),
'chassisid': str(_chassisidbyswitch[switch])}
'chassisid': _chassisidbyswitch[switch]}
def _extract_neighbor_data_b(args):
"""Build LLDP data about elements connected to switch
@ -180,7 +183,8 @@ def _extract_neighbor_data_b(args):
sid = str(sysid[1][6:])
idxtoifname = {}
idxtoportid = {}
_chassisidbyswitch[switch] = list(conn.walk('1.0.8802.1.1.2.1.3.2'))[0][1]
_chassisidbyswitch[switch] = sanitize(list(
conn.walk('1.0.8802.1.1.2.1.3.2'))[0][1])
for oidindex in conn.walk('1.0.8802.1.1.2.1.3.7.1.3'):
idx = oidindex[0][-1]
idxtoportid[idx] = sanitize(oidindex[1])