Verified Commit 032bb8c8 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Generic.get_inventory. Add get_chassis_sensors method for return chassis sensor.

parent e6ae586b
Pipeline #36641 failed with stages
in 20 seconds
......@@ -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,8 +15,4 @@ class Script(BaseScript):
cache = True
interface = IGetChassisID
def execute_snmp(self):
# 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}]
SNMP_GET_OIDS = {"SNMP": ["1.3.6.1.4.1.35419.1.1.6.0"]}
......@@ -16,26 +16,8 @@ class Script(BaseScript):
requires = []
def execute_snmp(self, interfaces=None):
index = [1, 2, 3, 4, 5]
result = []
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 += [
return [
{
"interface": "eth0",
"admin_status": True,
......@@ -45,4 +27,3 @@ class Script(BaseScript):
"out_speed": 10000,
}
]
return result
......@@ -16,15 +16,18 @@ class Script(BaseScript):
def execute_snmp(self):
interfaces = [
return [
{
"type": "physical",
"name": "eth0",
"admin_status": True,
"oper_status": True,
"mac": self.snmp.get("1.3.6.1.4.1.35419.1.1.6.0"),
"snmp_ifindex": 100,
"subinterfaces": [],
"interfaces": [
{
"type": "physical",
"name": "eth0",
"admin_status": True,
"oper_status": True,
"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):
"status": True,
"description": "Датчик числа импульсов",
"measurement": "Scalar",
"labels": ["noc::sensor::placement::external", "noc::sensor::mode::counter"],
"snmp_oid": "1.3.6.1.4.1.35419.20.1.160.0",
},
]
......@@ -47,10 +48,3 @@ class Script(BaseScript):
}
]
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
......@@ -11,76 +11,3 @@ from noc.sa.profiles.Generic.get_metrics import Script as GetMetricsScript, metr
class Script(GetMetricsScript):
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
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# Copyright (C) 2007-2022 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python Modules
from typing import Dict
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinventory import IGetInventory
......@@ -14,6 +17,21 @@ class Script(BaseScript):
name = "Generic.get_inventory"
interface = IGetInventory
def get_sensor_labels(self) -> Dict[str, 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):
v = self.scripts.get_version()
serial = None
......@@ -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):
return self.get_inv_from_version()
return self.processed_inventory()
def execute_cli(self):
return self.get_inv_from_version()
return self.processed_inventory()
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