From 4319034b0fbdee58cce1a3bf840a6fb9b5a4a342 Mon Sep 17 00:00:00 2001 From: "Dmitry S. Luhtionov" Date: Wed, 26 Jun 2019 18:07:02 +0300 Subject: [PATCH] Update Eltex.ESR profile --- sa/profiles/Eltex/ESR/get_capabilities.py | 11 ++- sa/profiles/Eltex/ESR/get_interface_status.py | 8 +- sa/profiles/Eltex/ESR/get_interfaces.py | 12 ++- sa/profiles/Eltex/ESR/get_inventory.py | 8 +- sa/profiles/Eltex/ESR/get_lldp_neighbors.py | 95 +++++++++++++++++++ 5 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 sa/profiles/Eltex/ESR/get_lldp_neighbors.py diff --git a/sa/profiles/Eltex/ESR/get_capabilities.py b/sa/profiles/Eltex/ESR/get_capabilities.py index 93bf292ed4..b5d84d99fb 100644 --- a/sa/profiles/Eltex/ESR/get_capabilities.py +++ b/sa/profiles/Eltex/ESR/get_capabilities.py @@ -2,12 +2,10 @@ # --------------------------------------------------------------------- # Eltex.ESR.get_capabilities # --------------------------------------------------------------------- -# Copyright (C) 2007-2017 The NOC Project +# Copyright (C) 2007-2019 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- -# Python modules -import re # NOC modules from noc.sa.profiles.Generic.get_capabilities import Script as BaseScript from noc.sa.profiles.Generic.get_capabilities import false_on_cli_error @@ -23,3 +21,10 @@ class Script(BaseScript): """ self.cli("show ipv6 neighbors") return True + + @false_on_cli_error + def has_lldp_cli(self): + """ + Check box has LLDP enabled + """ + return True diff --git a/sa/profiles/Eltex/ESR/get_interface_status.py b/sa/profiles/Eltex/ESR/get_interface_status.py index fcc3f72daa..fb3b719ae2 100644 --- a/sa/profiles/Eltex/ESR/get_interface_status.py +++ b/sa/profiles/Eltex/ESR/get_interface_status.py @@ -2,7 +2,7 @@ # --------------------------------------------------------------------- # Eltex.ESR.get_interface_status # --------------------------------------------------------------------- -# Copyright (C) 2007-2017 The NOC Project +# Copyright (C) 2007-2019 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -19,7 +19,11 @@ class Script(BaseScript): def execute(self, interface=None): r = [] c = self.cli("show interfaces status", cached=True) - for iface, astate, lstate, mtu, mac in parse_table(c): + # ESR-12V ver.1.0.9 produce random empty lines + c = "\n".join([s for s in c.split("\n") if s]) + for line in parse_table(c, allow_wrap=True): + iface = line[0] + lstate = line[2] if (interface is not None) and (interface != iface): continue r += [{ diff --git a/sa/profiles/Eltex/ESR/get_interfaces.py b/sa/profiles/Eltex/ESR/get_interfaces.py index 103eb5c865..189e91d65b 100644 --- a/sa/profiles/Eltex/ESR/get_interfaces.py +++ b/sa/profiles/Eltex/ESR/get_interfaces.py @@ -18,7 +18,7 @@ class Script(BaseScript): name = "Eltex.ESR.get_interfaces" interface = IGetInterfaces - rx_iface = re.compile("Interface\s+(?P\S+)") + rx_iface = re.compile(r"Interface\s+(?P\S+)") types = { "gi": "physical", @@ -53,7 +53,15 @@ class Script(BaseScript): ipv6_addresses[ifname] = ip interfaces = [] c = self.cli("show interfaces status", cached=True) - for ifname, astate, lstate, mtu, mac in parse_table(c): + # ESR-12V ver.1.0.9 produce random empty lines + c = "\n".join([s for s in c.split("\n") if s]) + for line in parse_table(c, allow_wrap=True): + # In some cases may be over 5 columns + ifname = line[0] + astate = line[1] + lstate = line[2] + mtu = line[3] + mac = line[4] description = descriptions.get(ifname) sub = { "name": ifname, diff --git a/sa/profiles/Eltex/ESR/get_inventory.py b/sa/profiles/Eltex/ESR/get_inventory.py index f468055579..110ea01144 100644 --- a/sa/profiles/Eltex/ESR/get_inventory.py +++ b/sa/profiles/Eltex/ESR/get_inventory.py @@ -2,7 +2,7 @@ # --------------------------------------------------------------------- # Eltex.ESR.get_inventory # --------------------------------------------------------------------- -# Copyright (C) 2007-2017 The NOC Project +# Copyright (C) 2007-2019 The NOC Project # See LICENSE for details # --------------------------------------------------------------------- @@ -27,6 +27,12 @@ class Script(BaseScript): r"System MAC address:\s+\S+\s*\n" r"System serial number:\s+(?P\S+)\s*\n") + """ + In ESR-12V ver.1.0.9 `show interfaces sfp` command produce this error: + + IS_LE check failed: sfps_size (0 <= 0) !!! + """ + def execute(self): c = self.scripts.get_system() match = self.rx_ver.search(c) diff --git a/sa/profiles/Eltex/ESR/get_lldp_neighbors.py b/sa/profiles/Eltex/ESR/get_lldp_neighbors.py new file mode 100644 index 0000000000..27446321bf --- /dev/null +++ b/sa/profiles/Eltex/ESR/get_lldp_neighbors.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +# --------------------------------------------------------------------- +# Eltex.ESR.get_lldp_neighbors +# --------------------------------------------------------------------- +# Copyright (C) 2007-2019 The NOC Project +# See LICENSE for details +# --------------------------------------------------------------------- + +# Python modules +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_INTERFACE_NAME, + LLDP_PORT_SUBTYPE_MAC, LLDP_PORT_SUBTYPE_NAME, LLDP_PORT_SUBTYPE_LOCAL, + LLDP_CAP_BRIDGE, LLDP_CAP_ROUTER, LLDP_CAP_STATION_ONLY, LLDP_CAP_WLAN_ACCESS_POINT +) + + +class Script(BaseScript): + name = "Eltex.ESR.get_lldp_neighbors" + interface = IGetLLDPNeighbors + + rx_neighbor = re.compile( + r"^(?Pgi\d+/\d+/\d+)\s+", + re.MULTILINE + ) + rx_detail = re.compile( + r"^\s*Index:\s+\d+\s*\n" + r"^\s*Local Interface:\s+\S+\s*\n" + r"^\s*Chassis type:\s+(?P.+)\s*\n" + r"^\s*Chassis ID:\s+(?P\S+)\s*\n" + r"^\s*Port type:\s+(?P.+)\s*\n" + r"^\s*Port ID:\s+(?P\S+)\s*\n" + r"^\s*Port description:(?P.*)\n" + r"^\s*Time to live:\s+\d+\s*\n" + r"^\s*System name:(?P.*)\n" + r"^\s*System Description:(?P.*)\s*\n" + r"^\s*Bridge:\s+(?P\S+)\s*\n" + r"^\s*Router:\s+(?P\S+)\s*\n" + r"^\s*Station:\s+(?P\S+)\s*\n" + r"^\s*Wlan:\s+(?P\S+)\s*\n", + re.MULTILINE + ) + CHASSIS_TYPES = { + "mac": LLDP_CHASSIS_SUBTYPE_MAC, + "ifname": LLDP_CHASSIS_SUBTYPE_INTERFACE_NAME + } + PORT_TYPES = { + "mac": LLDP_PORT_SUBTYPE_MAC, + "ifname": LLDP_PORT_SUBTYPE_NAME, + "local": LLDP_PORT_SUBTYPE_LOCAL + } + + def execute_cli(self): + r = [] + try: # 'Network | LLDP' always 'True' + v = self.cli("show lldp neighbor") + except self.CLISyntaxError: + return [] + for match in self.rx_neighbor.finditer(v): + local_interface = match.group("local_interface") + i = {"local_interface": local_interface, "neighbors": []} + v1 = self.cli("show lldp neighbors %s" % local_interface) + for match1 in self.rx_detail.finditer(v1): + remote_chassis_id = match1.group("chassis_id") + remote_chassis_id_subtype = self.CHASSIS_TYPES[match1.group("chassis_id_type").strip()] + remote_port = match1.group("port_id") + remote_port_subtype = self.PORT_TYPES[match1.group("port_id_type").strip()] + remote_capabilities = 0 + if match1.group("bridge") == "true": + remote_capabilities += LLDP_CAP_BRIDGE + if match1.group("router") == "true": + remote_capabilities += LLDP_CAP_ROUTER + if match1.group("station") == "true": + remote_capabilities += LLDP_CAP_STATION_ONLY + if match1.group("wlan") == "true": + remote_capabilities += LLDP_CAP_WLAN_ACCESS_POINT + n = { + "remote_chassis_id_subtype": remote_chassis_id_subtype, + "remote_chassis_id": remote_chassis_id, + "remote_port_subtype": remote_port_subtype, + "remote_port": remote_port, + "remote_capabilities": remote_capabilities + } + if match1.group("port_descr") and match1.group("port_descr").strip(): + n["remote_port_description"] = match1.group("port_descr").strip() + if match1.group("system_name") and match1.group("system_name").strip(): + n["remote_system_name"] = match1.group("system_name").strip() + if match1.group("system_descr") and match1.group("system_descr").strip(): + n["remote_system_description"] = match1.group("system_descr").strip() + i["neighbors"].append(n) + r.append(i) + return r -- GitLab