Verified Commit d899f3e6 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Rotek.BT.get_inventory. Convert to get_chassis_sensors.

parent a30f9161
Pipeline #36645 passed with stages
in 13 minutes and 38 seconds
# ---------------------------------------------------------------------
# Rotek.BT.get_interface_status_ex
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -9,7 +9,6 @@
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfacestatusex import IGetInterfaceStatusEx
from noc.core.validators import is_float
from noc.core.mib import mib
......@@ -28,26 +27,5 @@ class Script(BaseScript):
result += [{"interface": name, "admin_status": a_status, "oper_status": o_status}]
except Exception:
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
# ----------------------------------------------------------------------
# Rotek.BT.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.validators import is_float
from noc.core.mib import mib
......@@ -34,14 +33,13 @@ class Script(BaseScript):
raise NotImplementedError
def execute_snmp(self):
interfaces = []
try:
ifindex = self.snmp.get("1.3.6.1.2.1.2.2.1.1.1")
name = self.snmp.get(mib["IF-MIB::ifDescr", ifindex])
mac = self.snmp.get(mib["IF-MIB::ifPhysAddress", ifindex])
a_status = self.snmp.get(mib["IF-MIB::ifAdminStatus", ifindex])
o_status = self.snmp.get(mib["IF-MIB::ifOperStatus", ifindex])
interfaces += [
interfaces = [
{
"type": "physical",
"name": name,
......@@ -53,7 +51,7 @@ class Script(BaseScript):
]
except Exception:
mac = self.scripts.get_chassis_id()[0].get("first_chassis_mac")
interfaces += [
interfaces = [
{
"type": "physical",
"name": "st",
......@@ -63,30 +61,5 @@ class Script(BaseScript):
"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}]
# ---------------------------------------------------------------------
# Rotek.BT.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -14,8 +14,7 @@ class Script(BaseScript):
name = "Rotek.BT.get_inventory"
interface = IGetInventory
@staticmethod
def get_chassis_sensors():
def get_chassis_sensors_default(self):
r = [
# In
{
......@@ -80,7 +79,11 @@ class Script(BaseScript):
"status": True,
"description": "Дверь",
"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",
},
# v230
......@@ -89,6 +92,11 @@ class Script(BaseScript):
"status": True,
"description": "Флаг наличия сетевого напряжения AC 230В",
"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",
},
]
......@@ -114,7 +122,11 @@ class Script(BaseScript):
"status": True,
"description": "Ток потребления нагрузки",
"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",
},
{
......@@ -122,7 +134,11 @@ class Script(BaseScript):
"status": True,
"description": "ИБП. Напряжение на АКБ",
"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",
},
{
......@@ -130,7 +146,11 @@ class Script(BaseScript):
"status": True,
"description": "Ток заряда АКБ",
"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",
},
]
......@@ -144,6 +164,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Значение напряжения сети",
"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",
},
{
......@@ -151,6 +176,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Значение потребляемого тока",
"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",
},
{
......@@ -158,6 +188,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Значение потребляемой мощности",
"measurement": "Watt",
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::watt",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.10.0",
},
{
......@@ -165,6 +200,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. значение частоты сети",
"measurement": "Hertz",
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::freq",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.41752.911.10.1.13.9.0",
},
]
......@@ -177,17 +217,18 @@ class Script(BaseScript):
"status": bool(v),
"description": f"Электросчётчик. Суммарное значение потреблённой мощности по тарифу {num}",
"measurement": "Kilowatt-hour",
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::kwh",
"noc::sensor::target::power_load",
],
"snmp_oid": f"1.3.6.1.4.1.41752.911.10.1.13.{4 + num}.0",
}
]
return r
def execute_snmp(self):
r = self.get_inv_from_version()
def get_chassis_sensors(self):
if self.is_4250lsr:
sensors = self.get_chassis_sensors_4250lsr()
return self.get_chassis_sensors_4250lsr()
else:
sensors = self.get_chassis_sensors()
if sensors:
r[0]["sensors"] = sensors
return r
return self.get_chassis_sensors_default()
# ---------------------------------------------------------------------
# Rotek.BT.get_metrics
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript, metrics
from noc.core.validators import is_float
from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript
from noc.core.script.metrics import scale
......@@ -31,75 +30,3 @@ class Script(GetMetricsScript):
"1.3.6.1.4.1.41752.911.10.1.13.10.0": scale(0.000001, 2),
"1.3.6.1.4.1.41752.911.10.1.13.13.0": scale(0.001, 2),
}
@metrics(["Environment | Sensor Status"], volatile=False, access="S") # SNMP version
def get_sensor_status(self, metrics):
for metric in metrics:
port = metric.labels[0].rsplit("::", 1)[-1]
if "st" in port:
continue
value = 1
port = metric.labels[0].rsplit("::", 1)[-1]
status = self.snmp.get(f"1.3.6.1.4.1.41752.5.15.1.{metric.ifindex}.0")
if status is None:
continue
if metric.ifindex == 1 and int(status) == 0:
value = 0
elif metric.ifindex == 2:
if is_float(status) and (-55 < float(status) < 600):
value = 0
elif metric.ifindex in [4, 6] and float(status) > 0:
value = 0
elif metric.ifindex == 9 and int(status) != 2:
value = 0
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 not metric.labels:
continue
port = metric.labels[0].rsplit("::", 1)[-1]
if "temp" in port:
value = self.snmp.get(f"1.3.6.1.4.1.41752.5.15.1.{metric.ifindex}.0")
if value is None:
continue
if is_float(value):
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(f"1.3.6.1.4.1.41752.5.15.1.{metric.ifindex}.0")
if value is None:
continue
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Voltage", metric.labels),
labels=["noc::module::battery", f"noc::sensor::{port}"],
value=value,
multi=True,
)
@metrics(["Environment | Power | Input | Status"], volatile=False, access="S") # SNMP version
def get_power_input_status(self, metrics):
for metric in metrics:
value = 1
res = self.snmp.get("1.3.6.1.4.1.41752.5.15.1.9.0")
port = metric.labels[0].rsplit("::", 1)[-1]
if res not in [1, 2, 3]:
value = 0
self.set_metric(
id=("Environment | Power | Input | Status", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment