Commit aabb58ca authored by MaksimSmile13's avatar MaksimSmile13

Some Fix

parent 8defce82
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Rotek.RTBS.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
from noc.core.mib import mib
class Script(BaseScript):
name = "Eltex.UEP.get_chassis_id"
cache = True
interface = IGetChassisID
SNMP_GET_OIDS = {
"SNMP": [mib["IF-MIB::ifPhysAddress", 2]]
}
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# Rotek.BT.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_interfaces import Script as BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
class Script(BaseScript):
name = "Eltex.UEP.get_interfaces"
interface = IGetInterfaces
cache = True
MAX_REPETITIONS = 20
MAX_GETNEXT_RETIRES = 10
BULK = False
\ No newline at end of file
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Rotek.BT.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
class Script(BaseScript):
name = "Eltex.UEP.get_version"
cache = True
interface = IGetVersion
reuse_cli_session = False
keep_cli_session = False
def execute_snmp(self):
platform = self.snmp.get("1.3.6.1.4.1.35265.1.7.1.0")
version = self.snmp.get("1.3.6.1.2.1.1.1.0")
result = {
"vendor": "Eltex",
"version": version.split("#")[0].strip(),
"platform": platform.replace(" control module", "")}
return result
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Vendor: Eltex
# OS: UEP
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "Eltex.UEP"
# to one SNMP GET request
snmp_metrics_get_chunk = 2
# Timeout for snmp GET request
snmp_metrics_get_timeout = 5
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# MOXA.NPort.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
from noc.core.mib import mib
class Script(BaseScript):
name = "MOXA.NPort.get_chassis_id"
cache = True
interface = IGetChassisID
SNMP_GET_OIDS = {
"SNMP": [mib["IF-MIB::ifPhysAddress", 1]]
}
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# MOXA.NPort.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from collections import defaultdict
# NOC modules
from noc.sa.profiles.Generic.get_interfaces import Script as BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.lib.validators import is_mac
from noc.core.mac import MAC
from noc.core.mib import mib
from noc.core.ip import IPv4
class Script(BaseScript):
name = "MOXA.NPort.get_interfaces"
interface = IGetInterfaces
cache = True
INTERFACE_TYPES = {
6: "physical", # ethernetCsmacdб
33: "physical" # rs232
}
def execute_snmp(self, interface=None):
index = self.scripts.get_ifindexes()
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")
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]
i_type = self.get_interface_type(iface["type"])
if "." in iface["interface"]:
s = {
"name": iface["interface"],
"description": self.convert_description(iface.get("description", "")),
"type": i_type,
"enabled_afi": ["BRIDGE"],
"admin_status": iface["admin_status"],
"oper_status": iface["oper_status"],
"snmp_ifindex": l,
}
iface_name, num = iface["interface"].rsplit(".", 1)
if num.isdigit():
vlan_ids = int(iface["interface"].rsplit(".", 1)[-1])
if 1 <= vlan_ids < 4095:
s["vlan_ids"] = vlan_ids
if l in ip_ifaces:
s["ipv4_addresses"] = [IPv4(*ip_ifaces[l])]
s["enabled_afi"] = ["IPv4"]
if iface["mac_address"] and is_mac(iface["mac_address"]):
s["mac"] = MAC(iface["mac_address"])
subs[iface_name] += [s.copy()]
# r[-1]["subinterfaces"] += [s]
continue
i = {
"name": iface["interface"],
"description": self.convert_description(iface.get("description", "")),
"type": i_type,
"admin_status": iface["admin_status"],
"oper_status": iface["oper_status"],
"snmp_ifindex": l,
}
if iface["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}]
\ No newline at end of file
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# MOXA.NPort.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
from noc.core.script.http.base import HTTPError
from noc.lib.text import strip_html_tags
import re
class Script(BaseScript):
name = "MOXA.NPort.get_version"
cache = True
interface = IGetVersion
rx_info = re.compile(r"function window_onload\(\)\s+\{(?P<info>set(.*));\}", re.MULTILINE)
def execute_snmp(self):
try:
http_get = self.http.get("/main.htm")
match = self.rx_info.search(http_get)
if match:
res = match.group("info").split(";")
for v in res:
if "modelname" in v:
platform = v.split("\"")[3]
if "serialno" in v:
serial = v.split("\"")[3]
if "ver" in v:
version = v.split("\"")[3]
result = {
"vendor": "MOXA",
"version": version.strip(),
"platform": platform.strip(),
"attributes": {
"Serial Number": serial.strip()
}
}
except HTTPError:
platform = self.snmp.get("1.3.6.1.2.1.1.1.0")
return {"vendor": "MOXA",
"version": "",
"platform": platform}
return result
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Vendor: MOXA
# OS: NPort
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "MOXA.NPort"
# to one SNMP GET request
snmp_metrics_get_chunk = 2
# Timeout for snmp GET request
snmp_metrics_get_timeout = 5
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# RAD.DXC.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
from noc.core.mib import mib
class Script(BaseScript):
name = "RAD.DXC.get_chassis_id"
cache = True
interface = IGetChassisID
SNMP_GET_OIDS = {
"SNMP": [mib["IF-MIB::ifPhysAddress", 1]]
}
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------
# RAD.DXC.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from collections import defaultdict
# NOC modules
from noc.sa.profiles.Generic.get_interfaces import Script as BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.lib.validators import is_mac
from noc.core.mac import MAC
from noc.core.mib import mib
from noc.core.ip import IPv4
class Script(BaseScript):
name = "RAD.DXC.get_interfaces"
interface = IGetInterfaces
cache = True
INTERFACE_TYPES = {
1: "physical", # Ethernet
}
def execute_snmp(self, interface=None):
index = self.scripts.get_ifindexes()
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")
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]
i_type = self.get_interface_type(iface["type"])
if "." in iface["interface"]:
s = {
"name": iface["interface"],
"description": self.convert_description(iface.get("description", "")),
"type": i_type,
"enabled_afi": ["BRIDGE"],
"admin_status": iface["admin_status"],
"oper_status": iface["oper_status"],
"snmp_ifindex": l,
}
iface_name, num = iface["interface"].rsplit(".", 1)
if num.isdigit():
vlan_ids = int(iface["interface"].rsplit(".", 1)[-1])
if 1 <= vlan_ids < 4095:
s["vlan_ids"] = vlan_ids
if l in ip_ifaces:
s["ipv4_addresses"] = [IPv4(*ip_ifaces[l])]
s["enabled_afi"] = ["IPv4"]
if iface["mac_address"] and is_mac(iface["mac_address"]):
s["mac"] = MAC(iface["mac_address"])
subs[iface_name] += [s.copy()]
# r[-1]["subinterfaces"] += [s]
continue
i = {
"name": iface["interface"],
"description": self.convert_description(iface.get("description", "")),
"type": i_type,
"admin_status": iface["admin_status"],
"oper_status": iface["oper_status"],
"snmp_ifindex": l,
}
if iface["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}]
\ No newline at end of file
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# RAD.DXC.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
class Script(BaseScript):
name = "RAD.DXC.get_version"
cache = True
interface = IGetVersion
def execute_snmp(self):
res = self.snmp.get("1.3.6.1.2.1.1.1.0")
platform = res.split()[0].strip()
version = res.split()[1].strip()
return {"vendor": "RAD",
"version": version,
"platform": platform}
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Vendor: RAD
# OS: DXC
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "RAD.DXC"
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Settings for "pm" module
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.core.translation import ugettext as _
MODULE_NAME = _("Performance Management")
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# ManagedObject's dynamic dashboard
# ---------------------------------------------------------------------
# Copyright (C) 2007-2016 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from __future__ import absolute_import
# Third-Party modules
import demjson
from django.db.models import Q
from jinja2 import Environment, FileSystemLoader
# NOC modules
from .base import BaseDashboard
from noc.config import config
from noc.inv.models.interface import Interface
from noc.inv.models.subinterface import SubInterface
from noc.lib.text import split_alnum
from noc.pm.models.metrictype import MetricType
from noc.sa.models.managedobject import ManagedObject
TITLE_BAD_CHARS = u'"\\\n\r'
class MODashboard(BaseDashboard):
name = "mo"
def resolve_object(self, object):
o = ManagedObject.objects.filter(Q(id=object) | Q(bi_id=object))[:1]
if not o:
raise self.NotFound()
else:
return o[0]
def resolve_object_data(self, object):
def interface_profile_has_metrics(profile):
"""
Check interface profile has metrics
"""
for m in profile.metrics:
if m.enable_box or m.enable_periodic:
return True
return False
port_types = []
port_metrics = []
object_metrics = []
lags = []
subif = []
# Get all interface profiles with configurable metrics
all_ifaces = list(Interface.objects.filter(
managed_object=self.object.id
))
iprof = set(i.profile for i in all_ifaces)
# @todo: Order by priority
profiles = [p for p in iprof if interface_profile_has_metrics(p)]
# Create charts for configured interface metrics
for profile in profiles:
print profile
ifaces = [i for i in all_ifaces if i.profile == profile]
ports = []
for iface in sorted(ifaces, key=lambda el: split_alnum(el.name)):
if iface.type == 'SVI' and not iface.profile.allow_subinterface_metrics:
continue
if iface.type == u"aggregated" and iface.lag_members:
lags += [{
"name": iface.name,
"ports": [i.name for i in iface.lag_members],
"descr": self.str_cleanup(iface.description,
remove_letters=TITLE_BAD_CHARS) or "No description",
"status": ["status : ".join([i.name, i.status]) for i in iface.lag_members]
}]
continue
ports += [{"name": iface.name,
"descr": self.str_cleanup(iface.description, remove_letters=TITLE_BAD_CHARS),
"status": iface.status}]
if iface.profile.allow_subinterface_metrics:
subif += [{
"name": si.name,
"descr": self.str_cleanup(si.description, remove_letters=TITLE_BAD_CHARS)
} for si in SubInterface.objects.filter(interface=iface)]
if not ports:
continue
port_types += [{"type": profile.id, "name": profile.name,
"ports": ports}]
if self.object.object_profile.report_ping_rtt:
object_metrics += ["rtt"]
om = []
for m in (self.object.object_profile.metrics or []):
mt = MetricType.get_by_id(m["metric_type"])
if not mt or not (m.get("enable_periodic", False) or m.get("enable_box", False)):
continue
om += [mt.name]
object_metrics.extend(sorted(om))
return {"port_types": port_types,
"object_metrics": object_metrics,
"lags": lags,
"subifaces": subif}
def render(self):
context = {
"port_types": self.object_data["port_types"],
"object_metrics": self.object_data["object_metrics"],
"lags": self.object_data["lags"],
"device": self.object.name.replace('\"', ''),
"ip": self.object.address,
"platform": self.object.platform.name if self.object.platform else "Unknown platform",
"device_id": self.object.id,
"firmare_version": self.object.version.version if self.object.version else None,
"segment": self.object.segment.id,
"vendor": self.object.vendor or "Unknown version",
"subifaces": self.object_data["subifaces"],
"bi_id": self.object.bi_id,
"pool": self.object.pool.name,
"extra_template": self.extra_template,
"ping_interval": self.object.object_profile.ping_interval,
"discovery_interval": self.object.object_profile.periodic_discovery_interval
}
self.logger.info("Context with data: %s" % context)
j2_env = Environment(loader=FileSystemLoader(config.path.pm_templates))
tmpl = j2_env.get_template("dash_mo.j2")
data = tmpl.render(context)
render = demjson.decode(data)
return render
......@@ -124,7 +124,7 @@
{% for port in port_types -%}
{{ comma() }}
{
"collapse": false,
"collapse": true,
"editable": false,
"height": "250px",
"showTitle": true,
......@@ -142,7 +142,7 @@
,
{% set comma = joiner(",") -%}
{
"collapse": false,
"collapse": true,
"editable": false,
"height": "250px",
"showTitle": true,
......@@ -160,7 +160,7 @@
{% for lag in lags -%}
{{ comma() }}{
"collapse": false,
"collapse": true,
"editable": false,
"height": "250px",
"showTitle": true,
......@@ -179,6 +179,22 @@
{% include "row_errors.j2" with context -%}
{%endif%}
{%if port_types %}
,
{