...
 
Commits (4)
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Cisco.IOS.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.igetlacpneighbors import IGetLACPNeighbors
class Script(BaseScript):
name = "Cisco.IOS.get_lacp_neighbors"
interface = IGetLACPNeighbors
split_group_re = re.compile(r"\nChannel group\s+(\d+)")
split_group2_re = re.compile(r"\nChannel group\s+(\d+)\s+neighbors")
split_port_re = re.compile(r"Port:")
split_info_re = re.compile(
r"----.+Channel group\s*=\s*(?P<chan_group>\d+)\s.+"
r"Port-channel\s*=\s*(?P<port_chan>\S+)\s.+"
r"Local information:(?P<local_info>.+)"
r"Partner's information:(?P<part_info>.+)\n",
re.IGNORECASE | re.DOTALL,
)
def execute(self):
r = []
v = self.cli("show lacp sys-id")
sys_id = v.split(",")[1].strip()
try:
v = self.cli("show lacp internal")
except self.CLISyntaxError:
raise self.NotSupportedError()
port = {}
for block in self.split_group_re.split(v):
table = False
for l in block.splitlines():
if not l:
continue
l_l = l.split()
if table:
port[l_l[0]] = int(l_l[6][2:], 16)
if l_l[0] == "Port":
table = True
try:
v = self.cli("show lacp neighbor detail")
except self.CLISyntaxError:
raise self.NotSupportedError()
is_block = False
for block in self.split_group2_re.split(v)[1:]:
if not is_block:
chan_num = block
is_block = True
continue
bundle = []
for l in block.splitlines():
if not l:
continue
l_l = l.split()
if l_l[0] in port:
bundle += [
{
"interface": l_l[0],
"local_port_id": port[l_l[0]],
"remote_system_id": l_l[1].split(",")[1],
"remote_port_id": int(l_l[2], 16),
}
]
pass
"""
for port in self.split_port_re.split(block):
port_info = self.split_info_re.match(port)
if not port_info:
continue
local_info = port_info.group("local_info")
local_info = local_info.splitlines()[-1]
part_info = port_info.group("part_info")
part_info = part_info.splitlines()[-1]
group_interface = port_info.group("port_chan")
bundle += [{
"interface": local_info[0],
"local_port_id": local_info[6],
"remote_system_id": "",
"remote_port_id": part_info[6]
}]
"""
r += [
{
"lag_id": chan_num,
"interface": "Port-Channel" + chan_num,
"system_id": sys_id,
"bundle": bundle,
}
]
is_block = False
"show lacp internal detail"
"Local information:"
"Partner's information:"
return r
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Cisco.IOS.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.igetlacpneighbors import IGetLACPNeighbors
class Script(BaseScript):
name = "Cisco.IOS.get_lacp_neighbors"
interface = IGetLACPNeighbors
split_group_re = re.compile(r"\nChannel group\s+(\d+)")
split_group2_re = re.compile(r"\nChannel group\s+(\d+)\s+neighbors")
split_port_re = re.compile(r"Port:")
split_info_re = re.compile(
r"----.+Channel group\s*=\s*(?P<chan_group>\d+)\s.+"
r"Port-channel\s*=\s*(?P<port_chan>\S+)\s.+"
r"Local information:(?P<local_info>.+)"
r"Partner's information:(?P<part_info>.+)\n",
re.IGNORECASE | re.DOTALL,
)
rx_sys_id = re.compile(r",(?P<sys_id>\w{4}\.\w{4}\.\w{4})")
def execute(self):
r = []
v = self.cli("show lacp sys-id")
sys_id = self.rx_sys_id.search(v)
sys_id = sys_id.group("sys_id")
try:
v = self.cli("show lacp internal")
except self.CLISyntaxError:
raise self.NotSupportedError()
port = {}
for block in self.split_group_re.split(v):
table = False
for l in block.splitlines():
if not l:
continue
l_l = l.split()
if table:
port[l_l[0]] = int(l_l[6][2:], 16)
if l_l[0] == "Port":
table = True
try:
v = self.cli("show lacp neighbor detail")
except self.CLISyntaxError:
raise self.NotSupportedError()
is_block = False
for block in self.split_group2_re.split(v)[1:]:
if not is_block:
chan_num = block
is_block = True
continue
bundle = []
for l in block.splitlines():
if not l:
continue
l_l = l.split()
if l_l[0] in port:
bundle += [
{
"interface": l_l[0],
"local_port_id": port[l_l[0]],
"remote_system_id": l_l[1].split(",")[1],
"remote_port_id": int(l_l[2], 16),
}
]
pass
"""
for port in self.split_port_re.split(block):
port_info = self.split_info_re.match(port)
if not port_info:
continue
local_info = port_info.group("local_info")
local_info = local_info.splitlines()[-1]
part_info = port_info.group("part_info")
part_info = part_info.splitlines()[-1]
group_interface = port_info.group("port_chan")
bundle += [{
"interface": local_info[0],
"local_port_id": local_info[6],
"remote_system_id": "",
"remote_port_id": part_info[6]
}]
"""
r += [
{
"lag_id": chan_num,
"interface": "Port-Channel" + chan_num,
"system_id": sys_id,
"bundle": bundle,
}
]
is_block = False
"show lacp internal detail"
"Local information:"
"Partner's information:"
return r
......@@ -96,7 +96,7 @@ class Script(BaseScript):
# CISCO-ENTITY-MIB::entPhysicalModelName
p = self.snmp.get(mib["ENTITY-MIB::entPhysicalModelName.1"])
# WS-C4500X-32 return ' ', WS-C4900M return 'MIDPLANE'
if p is None or p.strip() in ["", "MIDPLANE"] or "\xff" in p:
if p is None or p.strip() in ["", "MIDPLANE"]:
# Found in WS-C4500X-32 and WS-C4900M
p = self.snmp.get(mib["ENTITY-MIB::entPhysicalModelName.1000"])
s = self.snmp.get(mib["ENTITY-MIB::entPhysicalSerialNum.1000"])
......
......@@ -38,9 +38,10 @@ class Script(BaseScript):
"/RPC2", data={"method": "magicBox.getSubModules", "params": None}, json=True
)
# @todo add PTZ to caps
for sm in r["params"].get("subModules", []):
if sm["ModuleName"] == "PTZ":
return sm["SoftwareVersion"]
if "subModules" in r["params"] and r["params"]["subModules"]:
for sm in r["params"]["subModules"]:
if sm["ModuleName"] == "PTZ":
return sm["SoftwareVersion"]
return None
def execute(self):
......