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 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): 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.