Commit 9b4cc23d authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Ttronics.KUB. Add sensor labels.

parent 993e6a31
......@@ -62,7 +62,7 @@ class Script(BaseScript):
return chassis
for ss in sensors:
if ss["name"] in sensor_labels and "labels" in ss:
ss["labels"] += sensor_labels[ss["name"]]
ss["labels"] = 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
......
......@@ -370,12 +370,13 @@ class Script(BaseScript):
"snmp_oid": "1.3.6.1.4.1.27514.103.0.24.0",
},
{
"name": "ups_battery_capasity",
"name": "ups_battery_state_of_charge",
"status": bool(v),
"description": "ИБП. Ёмкость батареи в %.",
"measurement": "Percent",
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::soc",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.27514.103.0.25.0",
......
# ---------------------------------------------------------------------
# Ttronics.KUB.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 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.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.4.1.51315.1.20.0")
if base:
return [{"first_chassis_mac": base, "last_chassis_mac": base}]
SNMP_GET_OIDS = {"SNMP": ["1.3.6.1.4.1.51315.1.20.0"]}
......@@ -17,39 +17,7 @@ class Script(BaseScript):
requires = []
def execute_snmp(self, interfaces=None):
result = []
for sensor in self.profile.SENSORS_TYPE.keys():
status = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % sensor, cached=True)
s_type = self.snmp.get(
"1.3.6.1.4.1.51315.1.%s.0" % self.profile.SENSORS_TYPE.get(sensor), cached=True
)
s_status = False
if status == 0:
s_status = True
result += [
{
"interface": "%s/%s" % (s_type, sensor - 2) if s_type in [0, 1, 2] else s_type,
"admin_status": s_status,
"oper_status": s_status,
}
]
for sensor2 in self.profile.SENSORS_TYPE2.keys():
status2 = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % sensor2, cached=True)
s2_status = False
if sensor2 == 1:
if status2 != -128:
s2_status = True
else:
if status2 == 0:
s2_status = True
result += [
{
"interface": self.profile.SENSORS_TYPE2.get(sensor2),
"admin_status": s2_status,
"oper_status": s2_status,
}
]
result += [
return [
{
"interface": "eth0",
"admin_status": True,
......@@ -59,4 +27,3 @@ class Script(BaseScript):
"out_speed": 10000,
}
]
return result
......@@ -13,68 +13,21 @@ from noc.sa.interfaces.igetinterfaces import IGetInterfaces
class Script(BaseScript):
name = "Ttronics.KUB.get_interfaces"
interface = IGetInterfaces
cache = True
def status(self, index):
return self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % index, cached=True)
def execute_snmp(self):
interfaces = []
for sensor in self.profile.SENSORS_TYPE.keys():
status = self.status(sensor)
s_type = self.snmp.get(
"1.3.6.1.4.1.51315.1.%s.0" % self.profile.SENSORS_TYPE.get(sensor), cached=True
)
s_status = False
if status == 0:
s_status = True
print(sensor)
interfaces += [
{
"type": "physical",
"name": "%s/%s" % (s_type, sensor - 2) if s_type in [0, 1, 2] else s_type,
"admin_status": s_status,
"oper_status": s_status,
"snmp_ifindex": sensor,
"description": "%s %s" % (self.profile.PORT_TYPE.get(s_type), sensor - 2)
if s_type in [0, 1, 2]
else self.profile.PORT_TYPE.get(s_type),
"subinterfaces": [],
}
]
for sensor2 in self.profile.SENSORS_TYPE2.keys():
status2 = self.status(sensor)
s2_status = False
if sensor2 == 1:
if status2 != -128:
s2_status = True
else:
if status2 == 0:
s2_status = True
interfaces += [
{
"type": "physical",
"name": self.profile.SENSORS_TYPE2.get(sensor2),
"admin_status": s2_status,
"oper_status": s2_status,
"snmp_ifindex": sensor2,
"description": "Вход датчика температуры"
if sensor2 == 1
else self.profile.PORT_TYPE.get(sensor2),
"subinterfaces": [],
}
]
mac = self.snmp.get("1.3.6.1.4.1.51315.1.20.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}]
......@@ -20,14 +20,26 @@ class Script(BaseScript):
"units": "Volt AC",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::voltage"],
},
1: {"type": "in", "units": "StatusEnum", "labels": ["noc::sensor::placement::external"]},
2: {"type": "relay", "units": "StatusEnum", "labels": ["noc::sensor::placement::external"]},
1: {
"type": "in",
"units": "StatusEnum",
"labels": [
"noc::sensor::placement::external",
"noc::sensor::mode::flag",
"noc::sensor::target::door",
],
},
2: {
"type": "relay",
"units": "StatusEnum",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::relay"],
},
3: {
"type": "counter",
"units": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::counter"],
},
4: {"type": "vibration", "units": "Scalar", "labels": ["noc::sensor::placement::external"]},
4: {"type": "vibration", "units": "Scalar", "labels": ["noc::sensor::placement::internal"]},
}
def get_oid(self, p_type, num):
......@@ -59,7 +71,11 @@ class Script(BaseScript):
"status": 1,
"description": "Напряжение питания устройства",
"measurement": "Volt AC",
"labels": ["noc::sensor::placement::internal", "noc::sensor::mode::voltage"],
"labels": [
"noc::sensor::placement::internal",
"noc::sensor::mode::voltage",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.14.0",
},
]
......@@ -108,7 +124,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Значение напряжения сети",
"measurement": "Volt AC",
"labels": ["noc::sensor::placement::elmeter", "noc::sensor::mode::voltage"],
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::voltage",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.21.0",
},
{
......@@ -116,7 +136,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Значение потребляемого тока",
"measurement": "Ampere",
"labels": ["noc::sensor::placement::elmeter", "noc::sensor::mode::current"],
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::current",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.22.0",
},
{
......@@ -124,7 +148,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Суммарное значение потреблённой мощности по тарифу 1",
"measurement": "Kilowatt-hour",
"labels": ["noc::sensor::placement::elmeter", "noc::sensor::mode::kwh"],
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::counter",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.23.0",
},
{
......@@ -132,7 +160,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Суммарное значение потреблённой мощности по тарифу 2",
"measurement": "Kilowatt-hour",
"labels": ["noc::sensor::placement::elmeter", "noc::sensor::mode::kwh"],
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::counter",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.24.0",
},
{
......@@ -140,7 +172,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "Электросчётчик. Суммарное значение потреблённой мощности",
"measurement": "Kilowatt-hour",
"labels": ["noc::sensor::placement::elmeter", "noc::sensor::mode::kwh"],
"labels": [
"noc::sensor::placement::elmeter",
"noc::sensor::mode::counter",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.25.0",
},
]
......@@ -152,7 +188,7 @@ class Script(BaseScript):
"status": v != 0,
"description": "Флаг наличия связи с ИБП по порту RS-232",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::internal"],
"labels": ["noc::sensor::placement::internal", "noc::sensor::mode::flag"],
"snmp_oid": "1.3.6.1.4.1.51315.1.29.0",
},
]
......@@ -163,7 +199,7 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Текущее состояние ИБП",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::ups"],
"labels": ["noc::sensor::placement::ups", "noc::sensor::mode::flag"],
"snmp_oid": "1.3.6.1.4.1.51315.1.27.0",
},
{
......@@ -171,7 +207,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Текущее состояние батареи ИБП",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::flag",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.38.0",
},
{
......@@ -179,7 +219,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Текущий статус bypass",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::flag",
"noc::sensor::target::bypass",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.31.0",
},
{
......@@ -187,7 +231,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Текущий режим работы ИБП",
"measurement": "StatusEnum",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::target::supply",
"noc::sensor::mode::flag",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.32.0",
},
{
......@@ -195,7 +243,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Входное напряжение.",
"measurement": "Volt AC",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::voltage",
"noc::sensor::target::supply",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.33.0",
},
{
......@@ -203,7 +255,7 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Значение частоты сети",
"measurement": "Hertz",
"labels": ["noc::sensor::placement::ups"],
"labels": ["noc::sensor::placement::ups", "noc::sensor::target::supply"],
"snmp_oid": "1.3.6.1.4.1.51315.1.34.0",
},
{
......@@ -211,7 +263,11 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Выходное напряжение.",
"measurement": "Volt AC",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::voltage",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.35.0",
},
{
......@@ -219,15 +275,21 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Нагрузка ИБП в %.",
"measurement": "Percent",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.37.0",
},
{
"name": "ups_load_P",
"name": "ups_load_W",
"status": bool(v),
"description": "ИБП. Нагрузка ИБП в W.",
"measurement": "Watt",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::target::power_load",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.36.0",
},
{
......@@ -235,15 +297,23 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Напряжение батареи ИБП.",
"measurement": "Volt AC",
"labels": ["noc::sensor::placement::ups", "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.51315.1.40.0",
},
{
"name": "ups_battery_capasity",
"name": "ups_battery_state_of_charge",
"status": bool(v),
"description": "ИБП. Ёмкость батареи в %.",
"measurement": "Percent",
"labels": ["noc::sensor::placement::ups"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::soc",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.41.0",
},
{
......@@ -251,14 +321,26 @@ class Script(BaseScript):
"status": bool(v),
"description": "ИБП. Температура батареи",
"measurement": "Celsius",
"labels": ["noc::sensor::placement::ups", "noc::sensor::mode::temperature"],
"labels": [
"noc::sensor::placement::ups",
"noc::sensor::mode::temperature",
"noc::sensor::target::power_cell",
],
"snmp_oid": "1.3.6.1.4.1.51315.1.39.0",
},
]
return r
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",
"noc::sensor::target::door",
],
},
1: {
"type": "volt",
"units": "Volt AC",
......@@ -269,7 +351,7 @@ 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",
......@@ -323,10 +405,3 @@ class Script(BaseScript):
return self.get_femto_sensors()
else:
return self.get_nano_sensors()
def execute_snmp(self):
r = self.get_inv_from_version()
sensors = self.get_chassis_sensors()
if sensors:
r[0]["sensors"] = sensors
return r
......@@ -6,138 +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 = "Ttronics.KUB.get_metrics"
@metrics(["Environment | Sensor Status"], volatile=False, access="S") # SNMP version
def get_interface_admin_status(self, metrics):
for metric in metrics:
if metric.ifindex == 100:
continue
value = 1
status = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % metric.ifindex)
port = metric.labels[0].rsplit("::", 1)[-1]
if metric.ifindex == 1:
if status != -128:
value = 0
elif metric.ifindex == 3 and status == 0:
s_type = self.snmp.get("1.3.6.1.4.1.51315.1.15.0")
if s_type == 0 and status == 0:
value = 0
elif metric.ifindex == 4 and status == 0:
s_type = self.snmp.get("1.3.6.1.4.1.51315.1.16.0")
s_status = self.snmp.get("1.3.6.1.4.1.51315.1.2.0")
if s_type == 4 and s_status == 0:
value = s_status
else:
value = status
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 == 1:
value = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % metric.ifindex)
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:
if metric.ifindex == 29:
value = self.snmp.get("1.3.6.1.4.1.51315.1.40.0")
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,
scale=scale(0.1, 2),
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
port = metric.labels[0].rsplit("::", 1)[-1]
if metric.ifindex == 29:
status = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % metric.ifindex)
if status != 1:
value = self.snmp.get("1.3.6.1.4.1.51315.1.27.0")
elif metric.ifindex == 3:
s_type = self.snmp.get("1.3.6.1.4.1.51315.1.15.0")
status = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % metric.ifindex)
if s_type == 0 and status == 0:
value = 0
self.set_metric(
id=("Environment | Power | Input | Status", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(["Environment | Electric Current"], volatile=False, access="S") # SNMP version
def get_current_input(self, metrics):
for metric in metrics:
if metric.ifindex == 3:
value = self.snmp.get("1.3.6.1.4.1.51315.1.19")
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Electric Current", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(["Environment | Energy Consumption"], volatile=False, access="S") # SNMP version
def get_energy_cons(self, metrics):
for metric in metrics:
if metric.ifindex == 26:
value = self.snmp.get("1.3.6.1.4.1.51315.1.25.0")
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Energy Consumption", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(
["Environment | Battery | Capacity | Level"], volatile=False, access="S"
) # SNMP version
def get_battery_capacity(self, metrics):
for metric in metrics:
if metric.ifindex == 29:
status = self.snmp.get("1.3.6.1.4.1.51315.1.%s.0" % metric.ifindex)
if status != 1:
value = self.snmp.get("1.3.6.1.4.1.51315.1.41.0")
else:
value = self.snmp.get("1.3.6.1.4.1.51315.1.28.0")
port = metric.labels[0].rsplit("::", 1)[-1]
self.set_metric(
id=("Environment | Battery | Capacity | Level", metric.labels),
labels=[f"noc::sensor::{port}"],
value=value,
)
@metrics(["Environment | Pulse"], volatile=False, access="S") # SNMP version
def get_pulse(self, metrics):