Commit 993e6a31 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'patch-avs-qtech-sensor-labels' into 'master'

Qtech.BFC_PBIC_S.get_inventory. Add sensor labels.

See merge request noc/noc!6414
parents 417c1f19 2b7f9a9d
......@@ -6,7 +6,7 @@
# ---------------------------------------------------------------------
# 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
......@@ -15,7 +15,4 @@ class Script(BaseScript):
cache = True
interface = IGetChassisID
def execute_snmp(self):
base = self.snmp.get("1.3.6.1.3.55.1.2.2.0")
if base:
return [{"first_chassis_mac": base, "last_chassis_mac": base}]
SNMP_GET_OIDS = {"SNMP": ["1.3.6.1.3.55.1.2.2.0"]}
......@@ -17,56 +17,7 @@ class Script(BaseScript):
requires = []
def execute_snmp(self, interfaces=None):
result = []
temp = self.snmp.get("1.3.6.1.3.55.1.2.1.0", cached=True)
t_st = False
if -55 < temp < 600:
t_st = True
result += [{"interface": 21, "admin_status": t_st, "oper_status": t_st}]
for oid, value in self.snmp.getnext("1.3.6.1.3.55.1.3.1.1", max_retries=3, cached=True):
s_status = False
battery = False
descr = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % value)
try:
status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % value)
except self.snmp.SNMPError:
status = None
if descr in [0, 3]:
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % value)
if invert == 0 and status == 0:
s_status = True
elif invert == 1 and status == 1:
s_status = True
elif descr in [9, 10]:
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % value)
if descr == 9:
if invert == 0 and status == 0:
s_status = True
battery = True
elif invert == 1 and status == 1:
s_status = True
battery = True
elif invert == 0 and status == 1:
s_status = True
battery = True
elif invert == 1 and status == 0:
s_status = True
battery = True
if descr == 10:
if battery and invert == 0 and status == 0:
s_status = True
elif battery and invert == 1 and status == 1:
s_status = True
elif status:
s_status = True
result += [
{
"interface": "%s/%s" % (descr, value + 1) if descr == 0 else descr,
"admin_status": s_status,
"oper_status": s_status,
}
]
result += [
return [
{
"interface": "eth0",
"admin_status": True,
......@@ -76,4 +27,3 @@ class Script(BaseScript):
"out_speed": 10000,
}
]
return result
......@@ -16,78 +16,21 @@ class Script(BaseScript):
cache = True
def execute_snmp(self):
interfaces = []
temp = self.snmp.get("1.3.6.1.3.55.1.2.1.0", cached=True)
t_st = False
if -55 < temp < 600:
t_st = True
interfaces += [
{
"type": "physical",
"name": 21,
"admin_status": t_st,
"oper_status": t_st,
"snmp_ifindex": 21,
"description": "Выносной датчик температуры",
"subinterfaces": [],
}
]
for oid, value in self.snmp.getnext("1.3.6.1.3.55.1.3.1.1", max_retries=3, cached=True):
s_status = False
battery = False
descr = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % value)
status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % value)
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % value)
if descr in [0, 3]:
if invert == 0 and status == 0:
s_status = True
elif invert == 1 and status == 1:
s_status = True
elif descr in [9, 10]:
if descr == 9:
if invert == 0 and status == 0:
s_status = True
battery = True
elif invert == 1 and status == 1:
s_status = True
battery = True
elif invert == 0 and status == 1:
s_status = True
battery = True
elif invert == 1 and status == 0:
s_status = True
battery = True
if descr == 10:
if battery and invert == 0 and status == 0:
s_status = True
elif battery and invert == 1 and status == 1:
s_status = True
else:
if status > 0:
s_status = True
interfaces += [
{
"type": "physical",
"name": "%s/%s" % (descr, value + 1) if descr == 0 else descr,
"admin_status": s_status,
"oper_status": s_status,
"snmp_ifindex": value,
"description": "%s %s" % (self.profile.PORT_TYPE.get(descr), value + 1)
if descr == 0
else self.profile.PORT_TYPE.get(descr),
"subinterfaces": [],
}
]
mac = self.snmp.get("1.3.6.1.3.55.1.2.2.0")
interfaces += [
return [
{
"type": "physical",
"name": "eth0",
"admin_status": True,
"oper_status": True,
"mac": mac,
"snmp_ifindex": 100,
"subinterfaces": [],
"interfaces": [
{
"type": "physical",
"name": "eth0",
"admin_status": True,
"oper_status": True,
"mac": mac,
"snmp_ifindex": 100,
"subinterfaces": [],
}
]
}
]
return [{"interfaces": interfaces}]
# ---------------------------------------------------------------------
# Qtech.BFC_PBIC_S.get_inventory
# ---------------------------------------------------------------------
# Copyright (C) 2007-2021 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -15,7 +15,11 @@ class Script(BaseScript):
interface = IGetInventory
femto_input_config_map = {
0: {"type": "in", "units": "StatusEnum", "labels": ["noc::sensor::placement::external"]},
0: {
"type": "in",
"units": "StatusEnum",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::flag"],
},
1: {
"type": "volt",
"units": "Volt AC",
......@@ -26,16 +30,20 @@ class Script(BaseScript):
"units": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::counter"],
},
3: {"type": "vibration", "units": "Scalar", "labels": []},
3: {"type": "vibration", "units": "Scalar", "labels": ["noc::sensor::placement::internal"]},
4: {
"type": "impedance",
"units": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::impedance"],
},
9: {"type": "ups", "units": "Scalar", "labels": ["noc::sensor::placement::ups"]},
9: {
"type": "ups",
"units": "Scalar",
"labels": ["noc::sensor::placement::ups", "noc::sensor::mode::flag"],
},
}
def get_sensors(self):
def get_chassis_sensors(self):
"""
0 - Дискретный;
1 - Измерение напряжения;
......@@ -81,10 +89,3 @@ class Script(BaseScript):
}
]
return r
def execute_snmp(self):
r = self.get_inv_from_version()
sensors = self.get_sensors()
if sensors:
r[0]["sensors"] = sensors
return r
......@@ -6,135 +6,8 @@
# ---------------------------------------------------------------------
# NOC modules
from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript, metrics
from noc.core.script.metrics import scale
from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript
class Script(GetMetricsScript):
name = "Qtech.BFC_PBIC_S.get_metrics"
def get_battery(self):
for oid, key in self.snmp.getnext("1.3.6.1.3.55.1.3.1.1", max_retries=3, cached=True):
b_descr = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % key)
if b_descr == 9:
b_status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % key)
b_invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % key)
if b_invert == 0 and b_status == 0:
return True
elif b_invert == 1 and b_status == 1:
return True
elif b_invert == 0 and b_status == 1:
return True
elif b_invert == 1 and b_status == 0:
return True
@metrics(["Environment | Sensor Status"], volatile=False, access="S") # SNMP version
def get_interface_admin_status(self, metrics):
for metric in metrics:
value = 1
if metric.ifindex == 100:
continue
elif metric.ifindex == 21:
temp = self.snmp.get("1.3.6.1.3.55.1.2.1.0")
if -55 < temp < 600:
value = 0
else:
descr = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % metric.ifindex)
status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % metric.ifindex)
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % metric.ifindex)
if descr in [0, 3]:
if invert == 0 and status == 0:
value = 0
elif invert == 1 and status == 1:
value = 0
elif descr in [9, 10]:
if descr == 9:
if invert == 0 and status == 0:
value = 0
elif invert == 1 and status == 1:
value = 0
elif invert == 0 and status == 1:
value = 0
elif invert == 1 and status == 0:
value = 0
if descr == 10:
battery = self.get_battery()
if battery and invert == 0 and status == 0:
value = 0
elif battery and invert == 1 and status == 1:
value = 0
else:
if status > 0:
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 == 21:
value = self.snmp.get("1.3.6.1.3.55.1.2.1.0")
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.3.55.1.3.1.4.%s" % 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,
scale=scale(0.001, 2),
multi=True,
)
@metrics(["Environment | Pulse"], volatile=False, access="S") # SNMP version
def get_pulse(self, metrics):
for metric in metrics:
s_type = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % metric.ifindex)
if s_type == 2:
value = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % metric.ifindex)
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 = 1
descr = self.snmp.get("1.3.6.1.3.55.1.3.1.2.%s" % metric.ifindex)
if descr == 10:
status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % metric.ifindex)
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % metric.ifindex)
battery = self.get_battery()
if battery and invert == 0 and status == 0:
value = 0
elif battery and invert == 1 and status == 1:
value = 0
elif descr == 0:
status = self.snmp.get("1.3.6.1.3.55.1.3.1.4.%s" % metric.ifindex)
invert = self.snmp.get("1.3.6.1.3.55.1.3.1.3.%s" % metric.ifindex)
if invert == 0 and status == 0:
value = 0
elif invert == 1 and status == 1:
value = 0
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Power | Input | Status", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
......@@ -28,27 +28,6 @@ class Profile(BaseProfile):
rx_sensor_name = re.compile(r"^\d+$")
rx_discrete_name = re.compile(r"^\d+/\d+$")
PORT_TYPE = {
0: "Дискретный вход",
1: "Вход по напряжению",
2: "Вход счетчика импульсов",
3: "Вход датчика вибрации/удара",
4: "Вход по сопротивлению",
9: "Вход сигнала ИБП (Батарея разряжена)",
10: "Вход сигнала ИБП (Питание от сети)",
}
SENSOR_NAME = {
0: "discrete input",
1: "load",
2: "pulse",
3: "vibration/shock",
4: "resistance",
9: "battery",
10: "ups",
21: "temperature",
}
def convert_interface_name(self, s):
"""
>>> Profile().convert_interface_name("1")
......
# ---------------------------------------------------------------------
# Qtech.QFC.get_interface_status_ex
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -17,45 +17,8 @@ class Script(BaseScript):
requires = []
def execute_snmp(self, interfaces=None):
result = []
if self.is_lite:
for ifindex in self.profile.LITE_PORT_TYPE.keys():
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.27514.103.0.%s" % ifindex)
if ifindex in [5, 6, 7, 13] and status == 1:
s_status = 1
elif ifindex in [8, 9] and -55 < status < 600:
s_status = 1
elif ifindex == 27 and status > 0:
s_status = 1
result += [
{
"interface": self.profile.LITE_IFACE_NAME.get(ifindex),
"admin_status": s_status,
"oper_status": s_status,
}
]
else:
for ifindex in self.profile.LIGHT_PORT_TYPE.keys():
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.27514.102.0.%s" % ifindex)
if ifindex in [5, 6, 7, 8, 9, 10] and status == 1:
s_status = 1
elif ifindex in [13, 14] and -55 < status < 600:
s_status = 1
elif ifindex == 12 and status > 0:
s_status = 1
elif status and ifindex == 29 and int(status) > 0:
s_status = 1
result += [
{
"interface": self.profile.LIGHT_IFACE_NAME.get(ifindex),
"admin_status": s_status,
"oper_status": s_status,
}
]
result += [
return [
{
"interface": "eth0",
"admin_status": True,
......@@ -65,4 +28,3 @@ class Script(BaseScript):
"out_speed": 10000,
}
]
return result
# ----------------------------------------------------------------------
# Qtech.QFC.get_interfaces
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
......@@ -15,62 +15,23 @@ class Script(BaseScript):
interface = IGetInterfaces
def execute_snmp(self):
interfaces = []
if self.is_lite:
for ifindex in self.profile.LITE_PORT_TYPE.keys():
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.27514.103.0.%s" % ifindex)
if ifindex in [5, 6, 6, 13] and status == 1:
s_status = 1
elif ifindex in [8, 9] and -55 < status < 600:
s_status = 1
elif ifindex == 27 and status > 0:
s_status = 1
interfaces += [
{
"type": "physical",
"name": self.profile.LITE_IFACE_NAME.get(ifindex),
"admin_status": s_status,
"oper_status": s_status,
"snmp_ifindex": ifindex,
"description": self.profile.LITE_PORT_TYPE.get(ifindex),
"subinterfaces": [],
}
]
mac = self.snmp.get("1.3.6.1.4.1.27514.103.0.4.0")
else:
for ifindex in self.profile.LIGHT_PORT_TYPE.keys():
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.27514.102.0.%s" % ifindex)
if ifindex in [5, 6, 7, 8, 9, 10] and status == 1:
s_status = 1
elif ifindex in [13, 14] and -55 < status < 600:
s_status = 1
elif ifindex == 12 and status > 0:
s_status = 1
elif status and ifindex == 29 and int(status) > 0:
s_status = 1
interfaces += [
mac = self.snmp.get("1.3.6.1.4.1.27514.102.0.4.0")
return [
{
"interfaces": [
{
"type": "physical",
"name": self.profile.LIGHT_IFACE_NAME.get(ifindex),
"admin_status": s_status,
"oper_status": s_status,
"snmp_ifindex": ifindex,
"description": self.profile.LIGHT_PORT_TYPE.get(ifindex),
"name": "eth0",
"admin_status": True,
"oper_status": True,
"mac": mac,
"snmp_ifindex": 100,
"subinterfaces": [],
}
]
mac = self.snmp.get("1.3.6.1.4.1.27514.102.0.4.0")
interfaces += [
{
"type": "physical",
"name": "eth0",
"admin_status": True,
"oper_status": True,
"mac": mac,
"snmp_ifindex": 100,
"subinterfaces": [],
}
]
return [{"interfaces": interfaces}]
......@@ -25,6 +25,7 @@ class Script(BaseScript):
"status": 1,
"description": f"Цифровой вход номер {i}",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::external"],
"snmp_oid": f"1.3.6.1.4.1.27514.102.0.{4 + i}.0",
}
]
......@@ -36,6 +37,7 @@ class Script(BaseScript):
"status": 1,
"description": f"Реле {i}",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::relay"],
"snmp_oid": f"1.3.6.1.4.1.27514.102.0.{8 + i}.0",
}
]
......@@ -46,6 +48,11 @@ class Script(BaseScript):
"status": 1,
"description": "Напряжение питания устройства",
"measurement": "Volt AC",
"labels": [
"noc::sensor::placement::internal",
"noc::sensor::mode::voltage",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.27514.102.0.11.0",
},
# V230 state
......@@ -54,6 +61,11 @@ class Script(BaseScript):
"status": 1,
"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.27514.102.0.12.0",
},
# tempIN
......@@ -62,6 +74,10 @@ class Script(BaseScript):
"status": 1,
"description": "Значение температуры с внутреннего датчика",
"measurement": "Celsius",
"labels": [
"noc::sensor::placement::internal",
"noc::sensor::mode::temperature",
],
"snmp_oid": "1.3.6.1.4.1.27514.102.0.13.0",
},
]
......@@ -73,6 +89,10 @@ class Script(BaseScript):
"status": bool(v),