From fe40346f21ab9639ac1505d6d52304ad10514e2a Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 12 May 2020 17:15:50 +0300 Subject: [PATCH 1/3] Fix Orion.NOS.get_lldp_neighbors script --- sa/profiles/Orion/NOS/get_lldp_neighbors.py | 63 +++++++++++++-------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/sa/profiles/Orion/NOS/get_lldp_neighbors.py b/sa/profiles/Orion/NOS/get_lldp_neighbors.py index 8d0243a407..a7980fd52b 100644 --- a/sa/profiles/Orion/NOS/get_lldp_neighbors.py +++ b/sa/profiles/Orion/NOS/get_lldp_neighbors.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # --------------------------------------------------------------------- # Orion.NOS.get_lldp_neighbors # --------------------------------------------------------------------- @@ -11,6 +12,23 @@ import re # NOC modules from noc.core.script.base import BaseScript from noc.sa.interfaces.igetlldpneighbors import IGetLLDPNeighbors +from noc.core.lldp import ( + LLDP_CHASSIS_SUBTYPE_MAC, + LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS, + LLDP_CHASSIS_SUBTYPE_INTERFACE_NAME, + LLDP_PORT_SUBTYPE_ALIAS, + LLDP_PORT_SUBTYPE_COMPONENT, + LLDP_PORT_SUBTYPE_MAC, + LLDP_PORT_SUBTYPE_NAME, + LLDP_PORT_SUBTYPE_LOCAL, + LLDP_CAP_OTHER, + LLDP_CAP_REPEATER, + LLDP_CAP_BRIDGE, + LLDP_CAP_ROUTER, + LLDP_CAP_TELEPHONE, + LLDP_CAP_STATION_ONLY, + lldp_caps_to_bits, +) class Script(BaseScript): @@ -34,7 +52,7 @@ class Script(BaseScript): r"^PortIdSubtype\s*:\s+(?P\S+)\s*\n" r"^PortId\s*:\s+(?P.+)\n" r"^PortDesc\s*:\s+(?P.+)\n" - r"^SysName\s*:\s+(?P.+)\n" + r"^SysName\s*:\s+(?P.*)\n" r"^SysDesc\s*:\s+(?P(.+\n)+)" r"^SysCapSupported\s*:.*\n" r"^SysCapEnabled\s*:\s+(?P.+)\s*\n", @@ -50,16 +68,18 @@ class Script(BaseScript): v = self.cli("show lldp remote detail") for match in self.rx_int.finditer(v): neighbor = { - "remote_chassis_id_subtype": {"macAddress": 4, "networkAddress": 5, "ifName": 6}[ - match.group("chassis_subtype") - ], + "remote_chassis_id_subtype": { + "macAddress": LLDP_CHASSIS_SUBTYPE_MAC, + "networkAddress": LLDP_CHASSIS_SUBTYPE_NETWORK_ADDRESS, + "ifName": LLDP_CHASSIS_SUBTYPE_INTERFACE_NAME, + }[match.group("chassis_subtype")], # "remote_chassis_id": match.group("chassis_id"), "remote_port_subtype": { - "ifAlias": 1, - "macAddress": 3, - "ifName": 5, - "portComponent": 5, - "local": 7, + "ifAlias": LLDP_PORT_SUBTYPE_ALIAS, + "macAddress": LLDP_PORT_SUBTYPE_MAC, + "ifName": LLDP_PORT_SUBTYPE_NAME, + "portComponent": LLDP_PORT_SUBTYPE_COMPONENT, + "local": LLDP_PORT_SUBTYPE_LOCAL, }[match.group("port_subtype")], "remote_port": match.group("port_id"), } @@ -76,20 +96,17 @@ class Script(BaseScript): if match.group("sys_descr").strip(): p = match.group("sys_descr").strip() neighbor["remote_system_description"] = re.sub(r"\n\s{30}", "", p) - caps = 0 - for c in match.group("caps").split(","): - c = c.strip() - if not c: - break - caps |= { - "Other": 1, - "Repeater/Hub": 2, - "Bridge/Switch": 4, - "Wireless LAN": 8, - "Router": 16, - "Telephone": 32, - "Station": 128, - }[c] + caps = lldp_caps_to_bits( + match.group("caps").strip().split(","), + { + "Other": LLDP_CAP_OTHER, + "Repeater/Hub": LLDP_CAP_REPEATER, + "Bridge/Switch": LLDP_CAP_BRIDGE, + "Router": LLDP_CAP_ROUTER, + "Telephone": LLDP_CAP_TELEPHONE, + "Station": LLDP_CAP_STATION_ONLY, + }, + ) neighbor["remote_capabilities"] = caps result += [{"local_interface": match.group("interface"), "neighbors": [neighbor]}] return result -- GitLab From b97446395843bf8a4a4bd67b849ae993491c509f Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 12 May 2020 17:19:06 +0300 Subject: [PATCH 2/3] Fix --- sa/profiles/Orion/NOS/get_lldp_neighbors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sa/profiles/Orion/NOS/get_lldp_neighbors.py b/sa/profiles/Orion/NOS/get_lldp_neighbors.py index a7980fd52b..c0cdcac128 100644 --- a/sa/profiles/Orion/NOS/get_lldp_neighbors.py +++ b/sa/profiles/Orion/NOS/get_lldp_neighbors.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # --------------------------------------------------------------------- # Orion.NOS.get_lldp_neighbors # --------------------------------------------------------------------- -- GitLab From 77750684770521ea4ea338b32a7b682506edd0cf Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 12 May 2020 18:23:23 +0300 Subject: [PATCH 3/3] Fix --- sa/profiles/Orion/NOS/get_lldp_neighbors.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sa/profiles/Orion/NOS/get_lldp_neighbors.py b/sa/profiles/Orion/NOS/get_lldp_neighbors.py index c0cdcac128..ba228aa2ca 100644 --- a/sa/profiles/Orion/NOS/get_lldp_neighbors.py +++ b/sa/profiles/Orion/NOS/get_lldp_neighbors.py @@ -88,13 +88,16 @@ class Script(BaseScript): neighbor["remote_chassis_id"] = chassis[match.group("interface")] if match.group("port_descr").strip(): p = match.group("port_descr").strip() - neighbor["remote_port_description"] = re.sub(r"\n\s{30}", "", p) + if p != "N/A": + neighbor["remote_port_description"] = re.sub(r"\n\s{30}", "", p) if match.group("sys_name").strip(): p = match.group("sys_name").strip() - neighbor["remote_system_name"] = re.sub(r"\n\s{30}", "", p) + if p != "N/A": + neighbor["remote_system_name"] = re.sub(r"\n\s{30}", "", p) if match.group("sys_descr").strip(): p = match.group("sys_descr").strip() - neighbor["remote_system_description"] = re.sub(r"\n\s{30}", "", p) + if p != "N/A": + neighbor["remote_system_description"] = re.sub(r"\n\s{30}", "", p) caps = lldp_caps_to_bits( match.group("caps").strip().split(","), { -- GitLab