Commit 14e0f5fe authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

release-22.1:Backport!6410

parent 9dd1f98a
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.sa.profiles.Generic.get_chassis_id import Script as BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID from noc.sa.interfaces.igetchassisid import IGetChassisID
...@@ -15,8 +15,4 @@ class Script(BaseScript): ...@@ -15,8 +15,4 @@ class Script(BaseScript):
cache = True cache = True
interface = IGetChassisID interface = IGetChassisID
def execute_snmp(self): SNMP_GET_OIDS = {"SNMP": ["1.3.6.1.4.1.35419.1.1.6.0"]}
# Try SNMP first
base = self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0")
if base:
return [{"first_chassis_mac": base, "last_chassis_mac": base}]
...@@ -16,26 +16,8 @@ class Script(BaseScript): ...@@ -16,26 +16,8 @@ class Script(BaseScript):
requires = [] requires = []
def execute_snmp(self, interfaces=None): def execute_snmp(self, interfaces=None):
index = [1, 2, 3, 4, 5]
result = [] return [
temp = self.snmp.get("1.3.6.1.4.1.35419.20.1.140.0", cached=True)
t_st = False
if temp != -104:
t_st = True
result += [{"interface": "Temperature", "admin_status": t_st, "oper_status": t_st}]
impulse = self.snmp.get("1.3.6.1.4.1.35419.20.1.160.0", cached=True)
i_st = False
if impulse != 0:
i_st = True
result += [{"interface": "Pulse", "admin_status": i_st, "oper_status": i_st}]
for ifindex in index:
status = self.snmp.get("1.3.6.1.4.1.35419.20.1.10%s.0" % ifindex)
if status == 0:
s_status = False
else:
s_status = True
result += [{"interface": ifindex, "admin_status": s_status, "oper_status": s_status}]
result += [
{ {
"interface": "eth0", "interface": "eth0",
"admin_status": True, "admin_status": True,
...@@ -45,4 +27,3 @@ class Script(BaseScript): ...@@ -45,4 +27,3 @@ class Script(BaseScript):
"out_speed": 10000, "out_speed": 10000,
} }
] ]
return result
...@@ -16,15 +16,18 @@ class Script(BaseScript): ...@@ -16,15 +16,18 @@ class Script(BaseScript):
def execute_snmp(self): def execute_snmp(self):
interfaces = [ return [
{ {
"type": "physical", "interfaces": [
"name": "eth0", {
"admin_status": True, "type": "physical",
"oper_status": True, "name": "eth0",
"mac": self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0"), "admin_status": True,
"snmp_ifindex": 100, "oper_status": True,
"subinterfaces": [], "mac": self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0"),
"snmp_ifindex": 100,
"subinterfaces": [],
}
]
} }
] ]
return [{"interfaces": interfaces}]
...@@ -30,6 +30,7 @@ class Script(BaseScript): ...@@ -30,6 +30,7 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "Датчик числа импульсов", "description": "Датчик числа импульсов",
"measurement": "Scalar", "measurement": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::counter"],
"snmp_oid": "1.3.6.1.4.1.35419.20.1.160.0", "snmp_oid": "1.3.6.1.4.1.35419.20.1.160.0",
}, },
] ]
...@@ -43,14 +44,8 @@ class Script(BaseScript): ...@@ -43,14 +44,8 @@ class Script(BaseScript):
"status": True, "status": True,
"description": f"Цифровой вход номер {i}", "description": f"Цифровой вход номер {i}",
"measurement": "Scalar", "measurement": "Scalar",
"labels": ["noc::sensor::placement::external"],
"snmp_oid": f"1.3.6.1.4.1.35419.20.1.{100 + i}.0", "snmp_oid": f"1.3.6.1.4.1.35419.20.1.{100 + i}.0",
} }
] ]
return r return r
def execute_snmp(self):
r = self.get_inv_from_version()
sensors = self.get_chassis_sensors()
if sensors:
r[0]["sensors"] = sensors
return r
...@@ -6,81 +6,8 @@ ...@@ -6,81 +6,8 @@
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# NOC modules # NOC modules
from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript, metrics from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript
class Script(GetMetricsScript): class Script(GetMetricsScript):
name = "ElectronR.KO01M.get_metrics" name = "ElectronR.KO01M.get_metrics"
@metrics(["Environment | Sensor Status"], volatile=False, access="S") # SNMP version
def get_sensor_status(self, metrics):
for metric in metrics:
value = 1
if metric.ifindex == 100:
continue
elif metric.ifindex == 140:
temp = self.snmp.get("1.3.6.1.4.1.35419.20.1.140.0", cached=True)
if -55 < temp < 600:
value = 0
elif metric.ifindex == 160:
impulse = self.snmp.get("1.3.6.1.4.1.35419.20.1.160.0", cached=True)
if impulse != 0:
value = 0
else:
res = self.snmp.get("1.3.6.1.4.1.35419.20.1.10%s.0" % metric.ifindex)
if res == 1:
value = 0
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Sensor Status", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(["Environment | Temperature"], volatile=False, access="S") # SNMP version
def get_temperature(self, metrics):
for metric in metrics:
if metric.ifindex == 140:
value = self.snmp.get("1.3.6.1.4.1.35419.20.1.%s.0" % metric.ifindex, cached=True)
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Temperature", metric.labels),
labels=[f"noc::module::{port}", f"noc::sensor::{port}"],
value=value,
multi=True,
)
@metrics(["Environment | Voltage"], volatile=False, access="S") # SNMP version
def get_voltage(self, metrics):
for metric in metrics:
value = self.snmp.get("1.3.6.1.4.1.35419.20.1.%s.0" % metric.ifindex)
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Voltage", metric.labels),
labels=[f"noc::module::{port}", f"noc::sensor::{port}"],
value=value,
multi=True,
)
@metrics(["Environment | Pulse"], volatile=False, access="S") # SNMP version
def get_pulse(self, metrics):
for metric in metrics:
if metric.ifindex == 160:
value = self.snmp.get("1.3.6.1.4.1.35419.20.1.%s.0" % metric.ifindex, cached=True)
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Pulse", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(["Environment | Power | Input | Status"], volatile=False, access="S") # SNMP version
def get_power_input_status(self, metrics):
for metric in metrics:
value = self.snmp.get("1.3.6.1.4.1.35419.20.1.10%s.0" % metric.ifindex, cached=True)
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Power | Input | Status", metric.labels),
labels=[f"noc::sensor::{port}"],
value=0 if value == 1 else 1,
)
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Generic.get_inventory # Generic.get_inventory
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Python Modules
from typing import Dict, List
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinventory import IGetInventory from noc.sa.interfaces.igetinventory import IGetInventory
...@@ -14,6 +17,21 @@ class Script(BaseScript): ...@@ -14,6 +17,21 @@ class Script(BaseScript):
name = "Generic.get_inventory" name = "Generic.get_inventory"
interface = IGetInventory interface = IGetInventory
def get_sensor_labels(self) -> Dict[str, List[str]]:
"""
For customizing. Return map sensor_name -> label.
For sensor classification
:return:
"""
return {}
def get_chassis_sensors(self):
"""
Return sensors on device chassis
:return:
"""
return []
def get_inv_from_version(self): def get_inv_from_version(self):
v = self.scripts.get_version() v = self.scripts.get_version()
serial = None serial = None
...@@ -33,8 +51,24 @@ class Script(BaseScript): ...@@ -33,8 +51,24 @@ class Script(BaseScript):
} }
] ]
def processed_inventory(self):
chassis = self.get_inv_from_version()
sensors = self.get_chassis_sensors()
if not sensors or not chassis:
return chassis
chassis[0]["sensors"] = sensors
sensor_labels = self.get_sensor_labels()
if not sensor_labels:
return chassis
for ss in sensors:
if ss["name"] in sensor_labels and "labels" in ss:
ss["labels"] += sensor_labels[ss["name"]]
elif ss["name"] in sensor_labels and "labels" not in ss:
ss["labels"] = sensor_labels[ss["name"]]
return chassis
def execute_snmp(self): def execute_snmp(self):
return self.get_inv_from_version() return self.processed_inventory()
def execute_cli(self): def execute_cli(self):
return self.get_inv_from_version() return self.processed_inventory()
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Rotek.BT.get_interface_status_ex # Rotek.BT.get_interface_status_ex
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfacestatusex import IGetInterfaceStatusEx from noc.sa.interfaces.igetinterfacestatusex import IGetInterfaceStatusEx
from noc.core.validators import is_float
from noc.core.mib import mib from noc.core.mib import mib
...@@ -28,26 +27,5 @@ class Script(BaseScript): ...@@ -28,26 +27,5 @@ class Script(BaseScript):
result += [{"interface": name, "admin_status": a_status, "oper_status": o_status}] result += [{"interface": name, "admin_status": a_status, "oper_status": o_status}]
except Exception: except Exception:
result += [{"interface": "st", "admin_status": True, "oper_status": True}] result += [{"interface": "st", "admin_status": True, "oper_status": True}]
for index in self.profile.PORT_TYPE.keys():
s_status = 0
status = self.snmp.get(f"1.3.6.1.4.1.41752.5.15.1.{index}.0")
if status is None:
continue
if index == 1 and int(status) == 0:
s_status = 1
elif index == 2:
if is_float(status) and (-55 < float(status) < 600):
s_status = 1
elif index in [4, 6] and float(status) > 0:
s_status = 1
elif index == 9 and int(status) != 2:
s_status = 1
result += [
{
"interface": self.profile.IFACE_NAME.get(index),
"admin_status": s_status,
"oper_status": s_status,
}
]
return result return result
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Rotek.BT.get_interfaces # Rotek.BT.get_interfaces
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# NOC modules # NOC modules
from noc.core.script.base import BaseScript from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.validators import is_float
from noc.core.mib import mib from noc.core.mib import mib
...@@ -34,14 +33,13 @@ class Script(BaseScript): ...@@ -34,14 +33,13 @@ class Script(BaseScript):
raise NotImplementedError raise NotImplementedError
def execute_snmp(self): def execute_snmp(self):
interfaces = []
try: try:
ifindex = self.snmp.get("1.3.6.1.2.1.2.2.1.1.1") ifindex = self.snmp.get("1.3.6.1.2.1.2.2.1.1.1")
name = self.snmp.get(mib["IF-MIB::ifDescr", ifindex]) name = self.snmp.get(mib["IF-MIB::ifDescr", ifindex])
mac = self.snmp.get(mib["IF-MIB::ifPhysAddress", ifindex]) mac = self.snmp.get(mib["IF-MIB::ifPhysAddress", ifindex])
a_status = self.snmp.get(mib["IF-MIB::ifAdminStatus", ifindex]) a_status = self.snmp.get(mib["IF-MIB::ifAdminStatus", ifindex])
o_status = self.snmp.get(mib["IF-MIB::ifOperStatus", ifindex]) o_status = self.snmp.get(mib["IF-MIB::ifOperStatus", ifindex])
interfaces += [ interfaces = [
{ {
"type": "physical", "type": "physical",
"name": name, "name": name,
...@@ -53,7 +51,7 @@ class Script(BaseScript): ...@@ -53,7 +51,7 @@ class Script(BaseScript):
] ]
except Exception: except Exception:
mac = self.scripts.get_chassis_id()[0].get("first_chassis_mac") mac = self.scripts.get_chassis_id()[0].get("first_chassis_mac")
interfaces += [ interfaces = [
{ {
"type": "physical", "type": "physical",
"name": "st", "name": "st",
...@@ -63,30 +61,5 @@ class Script(BaseScript): ...@@ -63,30 +61,5 @@ class Script(BaseScript):
"subinterfaces": [], "subinterfaces": [],
} }
] ]
if self.is_4250lsr:
return [{"interfaces": interfaces}]
for index in self.profile.PORT_TYPE.keys():
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.41752.5.15.1.%s.0" % index)
if index == 1 and int(status) == 0:
s_status = 1
elif index == 2:
if is_float(status) and (-55 < float(status) < 600):
s_status = 1
elif index in [4, 6] and float(status) > 0:
s_status = 1
elif index == 9 and int(status) != 2:
s_status = 1
interfaces += [
{
"type": "physical",
"name": self.profile.IFACE_NAME.get(index),
"admin_status": s_status,
"oper_status": s_status,
"snmp_ifindex": index,
"description": self.profile.PORT_TYPE.get(index),
"subinterfaces": [],
}
]
return [{"interfaces": interfaces}] return [{"interfaces": interfaces}]
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Rotek.BT.get_inventory # Rotek.BT.get_inventory
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -14,8 +14,7 @@ class Script(BaseScript): ...@@ -14,8 +14,7 @@ class Script(BaseScript):
name = "Rotek.BT.get_inventory" name = "Rotek.BT.get_inventory"
interface = IGetInventory interface = IGetInventory
@staticmethod def get_chassis_sensors_default(self):
def get_chassis_sensors():
r = [ r = [
# In # In
{ {
...@@ -80,7 +79,11 @@ class Script(BaseScript): ...@@ -80,7 +79,11 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "Дверь", "description": "Дверь",
"measurement": "StatusEnum", "measurement": "StatusEnum",
"labels": ["noc::sensor::placement::external"], "labels": [
"noc::sensor::placement::external",
"noc::sensor::mode::flag",
"noc::sensor::target::door",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.1.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.1.0",
}, },
# v230 # v230
...@@ -89,6 +92,11 @@ class Script(BaseScript): ...@@ -89,6 +92,11 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "Флаг наличия сетевого напряжения AC 230В", "description": "Флаг наличия сетевого напряжения AC 230В",
"measurement": "StatusEnum", "measurement": "StatusEnum",
"labels": [
"noc::sensor::placement::external",
"noc::sensor::mode::flag",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.9.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.9.0",
}, },
] ]
...@@ -114,7 +122,11 @@ class Script(BaseScript): ...@@ -114,7 +122,11 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "Ток потребления нагрузки", "description": "Ток потребления нагрузки",
"measurement": "Ampere", "measurement": "Ampere",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::current"], "labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::voltage",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.3.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.3.0",
}, },
{ {
...@@ -122,7 +134,11 @@ class Script(BaseScript): ...@@ -122,7 +134,11 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "ИБП. Напряжение на АКБ", "description": "ИБП. Напряжение на АКБ",
"measurement": "Volt AC", "measurement": "Volt AC",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::voltage"], "labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::voltage",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.6.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.6.0",
}, },
{ {
...@@ -130,7 +146,11 @@ class Script(BaseScript): ...@@ -130,7 +146,11 @@ class Script(BaseScript):
"status": True, "status": True,
"description": "Ток заряда АКБ", "description": "Ток заряда АКБ",
"measurement": "Ampere", "measurement": "Ampere",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::current"], "labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::current",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.5.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.5.0",
}, },
] ]
...@@ -144,6 +164,11 @@ class Script(BaseScript): ...@@ -144,6 +164,11 @@ class Script(BaseScript):
"status": bool(v), "status": bool(v),
"description": "Электросчётчик. Значение напряжения сети", "description": "Электросчётчик. Значение напряжения сети",
"measurement": "Volt AC", "measurement": "Volt AC",
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::voltage",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.2.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.2.0",
}, },
{ {
...@@ -151,6 +176,11 @@ class Script(BaseScript): ...@@ -151,6 +176,11 @@ class Script(BaseScript):
"status": bool(v), "status": bool(v),
"description": "Электросчётчик. Значение потребляемого тока", "description": "Электросчётчик. Значение потребляемого тока",
"measurement": "Ampere", "measurement": "Ampere",
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::current",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.3.0", "snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.3.0",
}, },
{ {
...@@ -158,6 +188,11 @@ class Script(BaseScript): ...@@ -158,6 +188,11 @@ class Script(BaseScript):
"status": bool(v), "status": bool(v),