From b6512a0de09db24c5b780a7f97f41a6826a28bb7 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Thu, 24 Mar 2022 19:12:44 +0100 Subject: [PATCH 1/3] Support sensors in JuniperMib --- python/nav/mibs/juniper_mib.py | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/python/nav/mibs/juniper_mib.py b/python/nav/mibs/juniper_mib.py index 9ea5ec9ac9..53d7bbc668 100644 --- a/python/nav/mibs/juniper_mib.py +++ b/python/nav/mibs/juniper_mib.py @@ -20,8 +20,10 @@ from nav.oids import OID from nav.smidumps import get_mib from nav.mibs.mibretriever import MibRetriever +from nav.mibs import reduce_index from nav.models.manage import PowerSupplyOrFan as FRU from nav.ipdevpoll.shadows import PowerSupplyOrFan, Device +from nav.models.manage import Sensor MEGABYTE = 1024**2 @@ -46,6 +48,15 @@ "standby": FRU.STATE_WARNING, } +SENSOR_TABLES = { + 'jnxOperatingTable': { + 'descr': 'jnxOperatingDescr', + 'unit': Sensor.UNIT_CELSIUS, + 'readout': 'jnxOperatingTemp', + 'internal_prefix': 'temperature', + }, +} + class JuniperMib(MibRetriever): """JUNIPER-MIB MibRetriever""" @@ -150,6 +161,64 @@ def get_fru_status(self, internal_id): get_fan_status = get_fru_status get_power_supply_status = get_fru_status + @defer.inlineCallbacks + def get_all_sensors(self): + """Returns a Deferred whose result is a list of sensor dictionaries""" + result = [] + for table, config in SENSOR_TABLES.items(): + sensors = yield self._get_sensors(config) + result.extend(sensors) + defer.returnValue(result) + + @defer.inlineCallbacks + def _get_sensors(self, config): + """ + Collects sensor columns according to the config dict, and translates + the results into sensor dicts. + + """ + columns = [config['descr'], config['readout']] + + result = ( + yield self.retrieve_columns(columns) + .addCallback(self.translate_result) + .addCallback(reduce_index) + ) + + sensors = ( + self._row_to_sensor(config, index, row) for index, row in result.items() + ) + + defer.returnValue([s for s in sensors if s]) + + def _row_to_sensor(self, config, index, row): + """ + Converts a collect SNMP table row into a sensor dict, using the + options defined in the config dict. + + """ + # Dont include sensor if temperature not set + readout = row.get(config['readout'], 0) + if not readout: + return + + internal_name = config['internal_prefix'] + str(index) + descr = row.get(config['descr'], internal_name) + " Temperature" + + mibobject = self.nodes.get(config['readout']) + readout_oid = str(mibobject.oid + str(index)) + + return { + 'oid': readout_oid, + 'unit_of_measurement': config['unit'], + 'precision': 0, + 'scale': None, + 'description': descr, + 'name': descr, + 'internal_name': internal_name, + 'mib': self.get_module_name(), + } + @staticmethod def _translate_fru_status_value(oper_status): """Translates the FRU status value from the MIB to a NAV PSU status value. From 81cfe96c2e205f42a96e4a656f856cde7cd13333 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Thu, 24 Mar 2022 19:13:10 +0100 Subject: [PATCH 2/3] add JuniperMib as a sensor mib to default config --- python/nav/ipdevpoll/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nav/ipdevpoll/config.py b/python/nav/ipdevpoll/config.py index d91b024fa3..5bb8dc1bf5 100644 --- a/python/nav/ipdevpoll/config.py +++ b/python/nav/ipdevpoll/config.py @@ -84,7 +84,7 @@ class IpdevpollConfig(NAVConfigParser): RARITAN_COMPUTER_INC = PDU2-MIB IBM = IBM-PDU-MIB RITTAL_WERK_RUDOLF_LOH_GMBH_COKG = RITTAL-CMC-III-MIB -JUNIPER_NETWORKS_INC = ENTITY-SENSOR-MIB JUNIPER-DOM-MIB +JUNIPER_NETWORKS_INC = ENTITY-SENSOR-MIB JUNIPER-DOM-MIB JUNIPER-MIB SUPERIOR_POWER_SOLUTIONS_HK_COLTD = Pwt3PhaseV1Mib ALCATEL_LUCENT_ENTERPRISE_FORMERLY_ALCATEL = ALCATEL-IND1-PORT-MIB COMPAQ = CPQPOWER-MIB From 6a7675f58a6d26aec9529bc52f01773a666d8373 Mon Sep 17 00:00:00 2001 From: Simon Oliver Tveit Date: Thu, 24 Mar 2022 19:13:37 +0100 Subject: [PATCH 3/3] Collect sensors from all Mibs Previously the code would stop after finding sensors from one of the Mibs gotten from self.mibfactory(). Now it goes through all the mibs and stores sensors from all of them This makes it possible to get JuniperDomMib sensors and JuniperMib temperature data but does it break other stuff? --- python/nav/ipdevpoll/plugins/sensors.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/nav/ipdevpoll/plugins/sensors.py b/python/nav/ipdevpoll/plugins/sensors.py index 389109be25..7defdb939e 100644 --- a/python/nav/ipdevpoll/plugins/sensors.py +++ b/python/nav/ipdevpoll/plugins/sensors.py @@ -77,7 +77,6 @@ def handle(self): "Found %d sensors from %s", len(all_sensors), type(mib).__name__ ) self._store_sensors(all_sensors) - break @defer.inlineCallbacks def mibfactory(self):