Commit 4762bf96 authored by MaksimSmile13's avatar MaksimSmile13

Some Fixes

parent 5302681a
......@@ -19,4 +19,3 @@ class Script(BaseScript):
SNMP_GET_OIDS = {
"SNMP": [mib["IF-MIB::ifPhysAddress", 2]]
}
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Vendor: Ericsson
# OS: SEOS
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
"""
For correct polling on snmp it is necessary to enable "snmp extended read" in settings
"""
name = "Ericsson.SEOS"
pattern_more = "^---(more)---"
pattern_unprivileged_prompt = \
r"^(?:\[(?P<context>\S+)\])?(?P<hostname>\S+)>"
pattern_prompt = r"^(?:\[(?P<context>\S+)\])?(?P<hostname>\S+)#"
pattern_syntax_error = r"% Invalid input at|% ERROR Invalid input detected"
command_disable_pager = "terminal length 0"
command_super = "enable"
command_enter_config = "configure"
command_leave_config = "exit"
rogue_chars = [re.compile(r"\x08{4,}\S+"), "\r"]
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_arp
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
"""
"""
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetarp import IGetARP
import re
class Script(BaseScript):
name = "Ericsson.SEOS.get_arp"
interface = IGetARP
rx_line = re.compile(
r"^\s*(?P<ip>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+ether\s+"
r"(?P<mac>\S+)\s+\S+\s+(?P<interface>\S+)\s*$", re.MULTILINE)
def execute(self, interface=None):
r = []
for match in self.rx_line.finditer(self.cli("show arp")):
iface = match.group("interface")
if (interface is not None) and (interface != iface):
continue
r += [match.groupdict()]
return r
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_chassis_id import Script as BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID
class Script(BaseScript):
name = "Ericsson.SEOS.get_chassis_id"
cache = True
interface = IGetChassisID
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_config
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetconfig import IGetConfig
class Script(BaseScript):
name = "Ericsson.SEOS.get_config"
cache = True
interface = IGetConfig
def execute_cli(self, **kwargs):
config = self.cli("show running-config", cached=True)
return self.cleaned_config(config)
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_ifindexes
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetifindexes import IGetIfindexes
from noc.sa.interfaces.base import InterfaceTypeError
from noc.core.mib import mib
class Script(BaseScript):
name = "Ericsson.SEOS.get_ifindexes"
interface = IGetIfindexes
cache = True
requires = []
MAX_GETNEXT_RETIRES = 0
def get_getnext_retires(self):
return self.MAX_GETNEXT_RETIRES
def execute_snmp(self):
r = {}
unknown_interfaces = []
d = {}
for doid, descr in self.snmp.getnext(mib["IF-MIB::ifDescr"], max_retries=self.get_getnext_retires()):
dindex = int(doid.split(".")[-1])
d[dindex] = descr
for oid, name in self.snmp.getnext(mib["IF-MIB::ifName"], max_retries=self.get_getnext_retires()):
index = int(oid.split(".")[-1])
if not name:
continue
if r.get(name):
name = "%s-%s" % (name, d[index])
try:
v = self.profile.convert_interface_name(name.strip())
except InterfaceTypeError as e:
self.logger.debug("Ignoring unknown interface %s: %s", name, e)
unknown_interfaces += [name]
continue
r[v] = index
if unknown_interfaces:
self.logger.info("%d unknown interfaces has been ignored", len(unknown_interfaces))
return r
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_interface_status_ex
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_interface_status_ex import Script as BaseScript
from noc.sa.interfaces.igetinterfacestatusex import IGetInterfaceStatusEx
from noc.sa.interfaces.base import InterfaceTypeError
from noc.core.mib import mib
class Script(BaseScript):
name = "Ericsson.SEOS.get_interface_status_ex"
interface = IGetInterfaceStatusEx
requires = []
def get_data(self, interfaces=None):
# ifIndex -> ifName mapping
r = {} # ifindex -> data
radio = {}
res = {}
unknown_interfaces = []
if interfaces:
for i in interfaces:
if "." in i["interface"]:
radio[i["ifindex"]] = {"interface": i["interface"]}
else:
r[i["ifindex"]] = {"interface": i["interface"]}
else:
for ifindex, name in self.get_iftable("IF-MIB::ifName"):
descr = self.snmp.get(mib["IF-MIB::ifDescr", ifindex])
try:
v = self.profile.convert_interface_name("%s/%s" % (name, descr))
except InterfaceTypeError as e:
self.logger.debug("Ignoring unknown interface %s: %s", "%s/%s" % (name, descr), e)
unknown_interfaces += [name]
continue
if "." in v:
radio[ifindex] = {"interface": v}
else:
r[ifindex] = {"interface": v}
if_index = list(r)
# Apply ifAdminStatus
self.apply_table(r, "IF-MIB::ifAdminStatus", "admin_status", lambda x: x == 1)
# Apply ifOperStatus
self.apply_table(r, "IF-MIB::ifOperStatus", "oper_status", lambda x: x == 1)
# Apply Radio ifAdminStatus
self.apply_table(radio, "1.3.6.1.4.1.193.81.3.4.3.1.2.1.8", "admin_status", lambda x: x == 3)
# Apply Radio ifOperStatus
self.apply_table(radio, "1.3.6.1.4.1.193.81.3.4.3.1.2.1.7", "oper_status", lambda x: x == 3)
# Apply dot3StatsDuplexStatus
self.apply_table(r, "EtherLike-MIB::dot3StatsDuplexStatus", "full_duplex", lambda x: x != 2)
# Apply ifSpeed
highspeed = set()
for ifindex, s in self.get_iftable("IF-MIB::ifSpeed", if_index):
ri = r.get(ifindex)
if ri and s is not None:
# s is None if OID is not exists
if self.is_high_speed(ri, s):
highspeed.add(ifindex)
elif s:
ri["in_speed"] = s // 1000
ri["out_speed"] = s // 1000
# Refer to ifHighSpeed if necessary
if highspeed:
for ifindex, s in self.get_iftable("IF-MIB::ifHighSpeed", if_index):
if ifindex in highspeed and s is not None: # s is None if OID is not exists
s = int(s)
if s:
r[ifindex]["in_speed"] = s * 1000
r[ifindex]["out_speed"] = s * 1000
# Log unknown interfaces
if unknown_interfaces:
self.logger.info("%d unknown interfaces has been ignored", len(unknown_interfaces))
for ifindex, rr in radio.iteritems():
rr["in_speed"] = self.snmp.get("1.3.6.1.4.1.193.81.3.4.1.1.14.1.7.1")
rr["out_speed"] = self.snmp.get("1.3.6.1.4.1.193.81.3.4.1.1.14.1.7.1")
res[ifindex] = rr
r.update(res)
return r.values()
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_interfaces
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from collections import defaultdict
import time
# NOC modules
from noc.sa.profiles.Generic.get_interfaces import Script as BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.mac import MAC
from noc.core.ip import IPv4
from noc.lib.validators import is_mac
class Script(BaseScript):
name = "Ericsson.SEOS.get_interfaces"
cache = True
interface = IGetInterfaces
INTERFACE_TYPES = {
1: "physical",
6: "physical", # ethernetCsmacd
18: "physical", # E1 - ds1
23: "physical", # ppp
24: "loopback", # softwareLoopback
117: "physical", # gigabitEthernet
131: "tunnel", # tunnel
135: "SVI", # l2vlan
161: "aggregated", # ieee8023adLag
53: "SVI", # propVirtual
54: "physical" # propMultiplexor
}
def execute_snmp(self, interface=None, last_ifname=None):
last_ifname = self.collect_ifnames()
# v = self.scripts.get_interface_status_ex()
index = self.scripts.get_ifindexes()
# index = self.get_ifindexes()
aggregated, portchannel_members = self.get_aggregated_ifaces()
ifaces = dict((index[i], {"interface": i}) for i in index)
# Apply ifAdminStatus
self.apply_table(ifaces, "IF-MIB::ifAdminStatus", "admin_status", lambda x: x == 1)
# Apply ifOperStatus
self.apply_table(ifaces, "IF-MIB::ifOperStatus", "oper_status", lambda x: x == 1)
# Apply PhysAddress
self.apply_table(ifaces, "IF-MIB::ifPhysAddress", "mac_address")
self.apply_table(ifaces, "IF-MIB::ifType", "type")
self.apply_table(ifaces, "IF-MIB::ifSpeed", "speed")
self.apply_table(ifaces, "IF-MIB::ifMtu", "mtu")
time.sleep(10)
self.apply_table(ifaces, "IF-MIB::ifAlias", "description")
ip_ifaces = self.get_ip_ifaces()
r = []
subs = defaultdict(list)
"""
IF-MIB::ifPhysAddress.1 = STRING:
IF-MIB::ifPhysAddress.2 = STRING: 0:21:5e:40:c2:50
IF-MIB::ifPhysAddress.3 = STRING: 0:21:5e:40:c2:52
"""
for l in ifaces:
iface = ifaces[l]
if last_ifname and iface["interface"] not in last_ifname:
continue
i_type = self.get_interface_type(iface["type"])
i = {
"name": iface["interface"],
"description": self.convert_description(iface.get("description", "")),
"type": i_type,
"admin_status": iface["admin_status"] if iface.get("admin_status") else False,
"oper_status": iface["oper_status"] if iface.get("oper_status") else iface["admin_status"]
if iface.get("admin_status") else False,
"snmp_ifindex": l,
}
if i["name"] in portchannel_members:
i["aggregated_interface"], lacp = portchannel_members[i["name"]]
if lacp:
i["enabled_protocols"] = ["LACP"]
if i["name"] in aggregated:
i["type"] = "aggregated"
if iface.get("mac_address") and is_mac(iface["mac_address"]):
i["mac"] = MAC(iface["mac_address"])
# sub = {"subinterfaces": [i.copy()]}
r += [i]
for l in r:
if l["name"] in subs:
l["subinterfaces"] = subs[l["name"]]
else:
l["subinterfaces"] = [
{
"name": l["name"],
"description": self.convert_description(l.get("description", "")),
"type": "SVI",
"enabled_afi": ["BRIDGE"]
if l["type"] in ["physical", "aggregated"] else [],
"admin_status": l["admin_status"],
"oper_status": l["oper_status"],
"snmp_ifindex": l["snmp_ifindex"],
}
]
if l["snmp_ifindex"] in ip_ifaces:
l["subinterfaces"][-1]["ipv4_addresses"] = [IPv4(*ip_ifaces[l["snmp_ifindex"]])]
l["subinterfaces"][-1]["enabled_afi"] = ["IPv4"]
return [{"interfaces": r}]
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2013 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinventory import IGetInventory
from noc.sa.interfaces.base import InterfaceTypeError
class Script(BaseScript):
name = "Ericsson.SEOS.get_inventory"
interface = IGetInventory
rx_trans = re.compile(
r"Port\s*:\s*(\S+)\s*XFP\s*\S+\s*Media\s*"
r"Type\s*:\s*([A-Za-z0-9 \/]+)\s*"
r"Redback\s*Approved\s*:\s*(YES|NO)\s*"
r"Diagnostic\s*Monitoring\s*:\s*\S+\s*"
r"CLEI\s*code\s*:\s*\S*\s*"
r"Serial\s*Number\s*:\s*(\S+)\s*\S+\s*:\s*(\S*)",
re.DOTALL | re.IGNORECASE | re.MULTILINE)
def execute(self):
objects = []
v = self.cli("show hardware")
media = self.cli("show port trans")
for l in v.splitlines():
if "backplane" in l:
objects += [{
"builtin": False,
"description": "Chassis backplane",
"number": 0,
"part_no": "SE600",
"serial": l.split()[2].strip(),
"vendor": "Ericsson",
"type": "CHASSIS"
}]
elif "fan tray" in l:
objects += [{
"builtin": False,
"description": "Fan Tray",
"number": 1,
"part_no": "SE600-FAN",
"serial": l.split()[3].strip(),
"vendor": "Ericsson",
"type": "FAN"
}]
elif "alarm card" in l:
objects += [{
"builtin": False,
"description": "Alarm Card",
"number": 0,
"part_no": "SE600-ALARM",
"serial": l.split()[3].strip(),
"vendor": "Ericsson",
"type": "ALRM"
}]
elif "-port" in l:
objects += [{
"builtin": False,
"description": l.split()[1].strip(),
"number": l.split()[0].strip(),
"part_no": l.split()[1].strip(),
"serial": l.split()[2].strip(),
"vendor": "Ericsson",
"type": "CARD"
}]
for match in self.rx_trans.findall(media):
if l.split()[0].strip() == match[0].split("/")[0]:
objects += [{
"builtin": False,
"description": match[1].strip() + " " +
match[4].strip(),
"number": match[0][2:],
"part_no": match[1].strip(),
"serial": match[3],
"vendor": "NoName",
"type": "XCVR"
}]
elif "xcrp" in l:
objects += [{
"builtin": False,
"description": l.split()[1].strip(),
"number": l.split()[0].strip(),
"part_no": l.split()[1].strip(),
"serial": l.split()[2].strip(),
"vendor": "Ericsson",
"type": "MGMT"
}]
return objects
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Eltex.MES.get_mac_address_table
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from __future__ import print_function
import re
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetmacaddresstable import IGetMACAddressTable
class Script(BaseScript):
name = "Ericsson.SEOS.get_mac_address_table"
interface = IGetMACAddressTable
rx_line = re.compile(
r"^\s*(?P<vlan_id>\d+)\s+(?P<mac>\S+)\s+(?P<interfaces>\S+)\s+(?P<type>\S+)", re.MULTILINE
)
def execute_snmp(self, interface=None, vlan=None, mac=None):
r = []
# Try SNMP first
vlan_oid = []
if mac is not None:
mac = mac.lower()
iface_name = {}
for v in self.snmp.get_tables(["1.3.6.1.2.1.31.1.1.1.1"]):
if v[1][:2] == 'fa' or v[1][:2] == 'gi' or v[1][:2] == 'te' or v[1][:2] == 'po':
name = v[1]
name = name.replace('fa', 'Fa ')
name = name.replace('gi', 'Gi ')
name = name.replace('te', 'Te ')
name = name.replace('po', 'Po ')
iface_name.update({v[0]: name})
for v in self.snmp.get_tables(["1.3.6.1.2.1.17.7.1.2.2.1.2"]):
vlan_oid.append(v[0])
# mac iface type
for v in self.snmp.get_tables(["1.3.6.1.2.1.17.4.3.1.1", "1.3.6.1.2.1.17.4.3.1.2",
"1.3.6.1.2.1.17.4.3.1.3"]):
if None in v:
continue
if v[1]:
chassis = ":".join(["%02x" % ord(c) for c in v[1]])
if mac is not None:
if chassis == mac:
pass
else:
continue
else:
continue
if int(v[3]) > 3 or int(v[3]) < 1:
continue
iface = iface_name[str(v[2])]
if interface is not None:
if iface == interface:
pass
else:
continue
for i in vlan_oid:
if v[0] in i:
vlan_id = int(i.split('.')[0])
break
if vlan is not None:
if vlan_id == vlan:
pass
else:
continue
r.append(
{
"interfaces": [iface],
"mac": chassis,
"type": {
"3": "D",
"2": "S",
"1": "S"
}[str(v[3])],
"vlan_id": vlan_id,
}
)
return r
def execute_cli(self, interface=None, vlan=None, mac=None):
r = []
# Fallback to CLI
cmd = "show mac address-table"
if mac is not None:
cmd += " address %s" % self.profile.convert_mac(mac)
if interface is not None:
cmd += " interface %s" % interface
if vlan is not None:
cmd += " vlan %s" % vlan
for match in self.rx_line.finditer(self.cli(cmd)):
interfaces = match.group("interfaces")
if interfaces == '0':
continue
r.append(
{
"vlan_id": match.group("vlan_id"),
"mac": match.group("mac"),
"interfaces": [interfaces],
"type": {
"dynamic": "D",
"static": "S",
"secure": "S",
"permanent": "S",
"self": "C"
}[match.group("type").lower()],
}
)
return r
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Ericsson.SEOS.get_version
# ---------------------------------------------------------------------
# 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.igetversion import IGetVersion
class Script(BaseScript):
name = "Ericsson.SEOS.get_version"
cache = True
interface = IGetVersion
rx_ver = re.compile(r"^Active SBL\s+:\s+CXP:\s+(?P<version>\S+.*)\s+"
r"^Passive (?:NPU|SBL)\s+:\s+CXP:\s+[\S\s]+"
r"^Active BNS\s+:\s+CXCR:\s+(?P<sw_backup>\S+.*)$",
re.MULTILINE)
def execute_snmp(self):
platform = self.snmp.get("1.3.6.1.2.1.1.1.0", cached=True)
active_rev = self.snmp.get("1.3.6.1.4.1.193.81.2.7.1.3.0", cached=True)
version = self.snmp.get("1.3.6.1.4.1.193.81.2.7.1.2.1.3.%s" % active_rev, cached=True)
serial = self.snmp.get("1.3.6.1.4.1.193.81.2.7.1.2.1.2.%s" % active_rev, cached=True)
return {
"vendor": "Ericsson",
"platform": platform.replace("Traffic Node", "TN"),
"version": version,
"attributes": {
"Serial Number": serial
}
}
def execute_cli(self):
ver = self.cli("show version", cached=True)
for match in self.rx_ver.finditer(ver):
version = match.group("version")
sw_backup = match.group("sw_backup")
return {
"vendor": "Ericsson",
"platform": "Mini-Link",
"version": version,
"attributes": {
"sw_backup": sw_backup
}
}
{
"$metric": "Radio | RxLevel",
"$type": "ifindex",
"oid": "1.3.6.1.4.1.193.81.3.4.3.1.3.1.10.{{ ifIndex }}",
"type": "gauge",
"scale": "scale(0.1)"
}
\ No newline at end of file
{
"$metric": "Radio | TxPower",
"$type": "ifindex",
"oid": "1.3.6.1.4.1.193.81.3.4.3.1.3.1.1.{{ ifIndex }}",
"type": "gauge"
}
\ No newline at end of file
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
File mode changed from 100755 to 100644
......@@ -19,4 +19,3 @@ class Script(BaseScript):
SNMP_GET_OIDS = {
"SNMP": [mib["IF-MIB::ifPhysAddress", 1]]
}