Commit ce1f30d4 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'cherry-pick-993e6a31' into 'release-22.1'

release-22.1:Backport!6414

See merge request !6415
parents e445d2ad 1cd1c289
...@@ -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,7 +15,4 @@ class Script(BaseScript): ...@@ -15,7 +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.3.55.1.2.2.0"]}
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}]
...@@ -17,56 +17,7 @@ class Script(BaseScript): ...@@ -17,56 +17,7 @@ class Script(BaseScript):
requires = [] requires = []
def execute_snmp(self, interfaces=None): def execute_snmp(self, interfaces=None):
result = [] return [
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 += [
{ {
"interface": "eth0", "interface": "eth0",
"admin_status": True, "admin_status": True,
...@@ -76,4 +27,3 @@ class Script(BaseScript): ...@@ -76,4 +27,3 @@ class Script(BaseScript):
"out_speed": 10000, "out_speed": 10000,
} }
] ]
return result
...@@ -16,78 +16,21 @@ class Script(BaseScript): ...@@ -16,78 +16,21 @@ class Script(BaseScript):
cache = True cache = True
def execute_snmp(self): 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") mac = self.snmp.get("1.3.6.1.3.55.1.2.2.0")
interfaces += [
return [
{ {
"type": "physical", "interfaces": [
"name": "eth0", {
"admin_status": True, "type": "physical",
"oper_status": True, "name": "eth0",
"mac": mac, "admin_status": True,
"snmp_ifindex": 100, "oper_status": True,
"subinterfaces": [], "mac": mac,
"snmp_ifindex": 100,
"subinterfaces": [],
}
]
} }
] ]
return [{"interfaces": interfaces}]
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Qtech.BFC_PBIC_S.get_inventory # Qtech.BFC_PBIC_S.get_inventory
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Copyright (C) 2007-2021 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -15,7 +15,11 @@ class Script(BaseScript): ...@@ -15,7 +15,11 @@ class Script(BaseScript):
interface = IGetInventory interface = IGetInventory
femto_input_config_map = { 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: { 1: {
"type": "volt", "type": "volt",
"units": "Volt AC", "units": "Volt AC",
...@@ -26,16 +30,20 @@ class Script(BaseScript): ...@@ -26,16 +30,20 @@ class Script(BaseScript):
"units": "Scalar", "units": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::counter"], "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: { 4: {
"type": "impedance", "type": "impedance",
"units": "Scalar", "units": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::impedance"], "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 - Дискретный; 0 - Дискретный;
1 - Измерение напряжения; 1 - Измерение напряжения;
...@@ -81,10 +89,3 @@ class Script(BaseScript): ...@@ -81,10 +89,3 @@ class Script(BaseScript):
} }
] ]
return r 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 @@ ...@@ -6,135 +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
from noc.core.script.metrics import scale
class Script(GetMetricsScript): class Script(GetMetricsScript):
name = "Qtech.BFC_PBIC_S.get_metrics" 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): ...@@ -28,27 +28,6 @@ class Profile(BaseProfile):
rx_sensor_name = re.compile(r"^\d+$") rx_sensor_name = re.compile(r"^\d+$")
rx_discrete_name = re.compile(r"^\d+/\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): def convert_interface_name(self, s):
""" """
>>> Profile().convert_interface_name("1") >>> Profile().convert_interface_name("1")
......
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Qtech.QFC.get_interface_status_ex # Qtech.QFC.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
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -17,45 +17,8 @@ class Script(BaseScript): ...@@ -17,45 +17,8 @@ class Script(BaseScript):
requires = [] requires = []
def execute_snmp(self, interfaces=None): 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", "interface": "eth0",
"admin_status": True, "admin_status": True,
...@@ -65,4 +28,3 @@ class Script(BaseScript): ...@@ -65,4 +28,3 @@ class Script(BaseScript):
"out_speed": 10000, "out_speed": 10000,
} }
] ]
return result
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Qtech.QFC.get_interfaces # Qtech.QFC.get_interfaces
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project # Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details # See LICENSE for details
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -15,62 +15,23 @@ class Script(BaseScript): ...@@ -15,62 +15,23 @@ class Script(BaseScript):
interface = IGetInterfaces interface = IGetInterfaces
def execute_snmp(self): def execute_snmp(self):
interfaces = []
if self.is_lite: 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") mac = self.snmp.get("1.3.6.1.4.1.27514.103.0.4.0")
else: else:
for ifindex in self.profile.LIGHT_PORT_TYPE.keys(): mac = self.snmp.get("1.3.6.1.4.1.27514.102.0.4.0")
s_status = 0
status = self.snmp.get("1.3.6.1.4.1.27514.102.0.%s" % ifindex) return [
if ifindex in [5, 6, 7, 8, 9, 10] and status == 1: {
s_status = 1 "interfaces": [
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 += [
{ {
"type": "physical", "type": "physical",
"name": self.profile.LIGHT_IFACE_NAME.get(ifindex), "name": "eth0",
"admin_status": s_status, "admin_status": True,
"oper_status": s_status, "oper_status": True,
"snmp_ifindex": ifindex, "mac": mac,