Example #1
0
    def _get_units(func, entity_physical_table):
        mib = EntityMib(Mock("AgentProxy"))

        def mock_retrieve(columns):
            return defer.succeed(entity_physical_table)

        mib.retrieve_columns = mock_retrieve
        df = getattr(mib, func)()
        assert df.called
        if isinstance(df.result, failure.Failure):
            df.result.raiseException()
        return df.result
Example #2
0
    def test_empty_logical_type_should_not_raise(self):
        mib = EntityMib(Mock('AgentProxy'))
        def mock_retrieve(columns):
            return defer.succeed(
                {1: {'entLogicalDescr': None,
                     'entLogicalType': None,
                     'entLogicalCommunity': None}}
                )

        mib.retrieve_columns = mock_retrieve
        df = mib.retrieve_alternate_bridge_mibs()
        self.assertTrue(df.called)
        if isinstance(df.result, failure.Failure):
            df.result.raiseException()
Example #3
0
    def test_empty_logical_type_should_not_raise(self):
        mib = EntityMib(Mock('AgentProxy'))
        def mock_retrieve(columns):
            return defer.succeed(
                {1: {'entLogicalDescr': None,
                     'entLogicalType': None,
                     'entLogicalCommunity': None}}
                )

        mib.retrieve_columns = mock_retrieve
        df = mib.retrieve_alternate_bridge_mibs()
        self.assertTrue(df.called)
        if isinstance(df.result, failure.Failure):
            df.result.raiseException()
Example #4
0
class EntitySensorMib(mibretriever.MibRetriever):
    from nav.smidumps.entity_sensor_mib import MIB as mib

    def __init__(self, agent_proxy):
        """Good old constructor..."""
        super(EntitySensorMib, self).__init__(agent_proxy)
        self.entity_mib = EntityMib(self.agent_proxy)

    def _get_sensors(self):
        """ Collect all sensors."""
        df = self.retrieve_columns([
            'entPhySensorType',
            'entPhySensorScale',
            'entPhySensorPrecision',
            'entPhySensorValue',
            'entPhySensorOperStatus',
            'entPhySensorUnitsDisplay',
        ])
        df.addCallback(reduce_index)
        return df

    def _collect_entity_names(self):
        """ Collect all entity-names on netbox."""
        df = self.entity_mib.retrieve_columns([
            'entPhysicalDescr',
            'entPhysicalName',
        ])
        df.addCallback(reduce_index)
        return df

    @defer.inlineCallbacks
    def _get_named_table(self, table_name):
        df = self.retrieve_table(table_name)
        df.addCallback(self.translate_result)
        ret_table = yield df
        named_table = EntityTable(ret_table)
        defer.returnValue(named_table)

    @defer.inlineCallbacks
    def get_phy_sensor_table(self):
        phy_sensor_table = yield self._get_named_table('entPhySensorTable')
        defer.returnValue(phy_sensor_table)

    @defer.inlineCallbacks
    def get_all_sensors(self):
        """ Collect all sensors and names on a netbox, and match
            sensors with names.

            Return a list with dictionaries, each dictionary
            represent a sensor."""
        sensors = yield self._get_sensors()
        entity_names = yield self._collect_entity_names()
        for idx, row in entity_names.items():
            if idx in sensors:
                sensors[idx]['entPhysicalDescr'] = row.get(
                    'entPhysicalDescr', None)
                sensors[idx]['entPhysicalName'] = row.get(
                    'entPhysicalName', None)
        result = []
        for row_id, row in sensors.items():
            row_oid = row.get(0, None)
            mibobject = self.nodes.get('entPhySensorValue', None)
            oid = str(mibobject.oid) + str(row_oid)
            unit_of_measurement = row.get('entPhySensorType', 2)
            precision = row.get('entPhySensorPrecision', 0)
            scale = row.get('entPhySensorScale', None)
            op_status = row.get('entPhySensorOperStatus', None)
            description = row.get('entPhysicalDescr', None)
            name = row.get('entPhysicalName', None)
            internal_name = name
            if op_status == 1:
                result.append({
                    'oid':
                    oid,
                    'unit_of_measurement':
                    UNITS_OF_MEASUREMENTS.get(unit_of_measurement, None),
                    'precision':
                    precision,
                    'scale':
                    DATA_SCALE.get(scale, None),
                    'description':
                    description,
                    'name':
                    name,
                    'internal_name':
                    internal_name,
                    'mib':
                    self.get_module_name(),
                })
        self._logger.debug('get_all_sensors: result=%s', result)
        defer.returnValue(result)
class EntitySensorMib(mibretriever.MibRetriever):
    from nav.smidumps.entity_sensor_mib import MIB as mib

    def __init__(self, agent_proxy):
        """Good old constructor..."""
        super(EntitySensorMib, self).__init__(agent_proxy)
        self.entity_mib = EntityMib(self.agent_proxy)

    def get_module_name(self):
        """Return this MIB-name"""
        return self.mib.get('moduleName', None)

    def _get_sensors(self):
        """ Collect all sensors."""
        df = self.retrieve_columns([
                'entPhySensorType',
                'entPhySensorScale',
                'entPhySensorPrecision',
                'entPhySensorValue',
                'entPhySensorOperStatus',
                'entPhySensorUnitsDisplay',
                ])
        df.addCallback(reduce_index)
        return df
            
    def _collect_entity_names(self):
        """ Collect all entity-names on netbox."""
        df = self.entity_mib.retrieve_columns([
                'entPhysicalDescr',
                'entPhysicalName',
                ])
        df.addCallback(reduce_index)
        return df

    @defer.inlineCallbacks
    def _get_named_table(self, table_name):
        df = self.retrieve_table(table_name)
        df.addCallback(self.translate_result)
        ret_table = yield df
        named_table = EntityTable(ret_table)
        defer.returnValue(named_table)

    @defer.inlineCallbacks
    def get_phy_sensor_table(self):
        phy_sensor_table = yield self._get_named_table('entPhySensorTable')
        defer.returnValue(phy_sensor_table)

    @defer.inlineCallbacks
    def get_all_sensors(self):
        """ Collect all sensors and names on a netbox, and match
            sensors with names.
            
            Return a list with dictionaries, each dictionary
            represent a sensor."""
        sensors = yield self._get_sensors()
        entity_names = yield self._collect_entity_names()
        for idx, row in entity_names.items():
            if idx in sensors:
                sensors[idx]['entPhysicalDescr'] = row.get(
                                                    'entPhysicalDescr',None)
                sensors[idx]['entPhysicalName'] = row.get(
                                                    'entPhysicalName', None)
        result = []
        for row_id, row in sensors.items():
            row_oid = row.get(0, None)
            mibobject = self.nodes.get('entPhySensorValue', None)
            oid = str(mibobject.oid) + str(row_oid)
            unit_of_measurement = row.get('entPhySensorType', 2)
            precision = row.get('entPhySensorPrecision', 0)
            scale = row.get('entPhySensorScale', None)
            op_status = row.get('entPhySensorOperStatus', None)
            description = row.get('entPhysicalDescr', None)
            name = row.get('entPhysicalName', None)
            internal_name = name
            if op_status == 1:
                result.append({
                    'oid': oid,
                    'unit_of_measurement': UNITS_OF_MEASUREMENTS.get(
                                                unit_of_measurement, None),
                    'precision': precision,
                    'scale': DATA_SCALE.get(scale, None),
                    'description': description,
                    'name': name,
                    'internal_name': internal_name,
                    'mib': self.get_module_name(),
                    })
        self._logger.debug('get_all_sensors: result=%s', result)
        defer.returnValue(result)
Example #6
0
class CiscoEntitySensorMib(mibretriever.MibRetriever):
    """This MIB should collect all present sensors from Cisco NEXUS boxes."""
    from nav.smidumps.cisco_entity_sensor_mib import MIB as mib

    def __init__(self, agent_proxy):
        """Good old constructor..."""
        super(CiscoEntitySensorMib, self).__init__(agent_proxy)
        self.entity_mib = EntityMib(self.agent_proxy)

    def get_module_name(self):
        """Get the name of this MIB"""
        return self.mib.get('moduleName', None)

    def _get_sensors(self):
        """ Collect all sensors from the box."""
        df = self.retrieve_columns([
            'entSensorType',
            'entSensorScale',
            'entSensorPrecision',
            'entSensorValue',
            'entSensorStatus',
            'entSensorValueTimeStamp',
            'entSensorValueUpdateRate',
            'entSensorMeasuredEntity',
        ])
        df.addCallback(reduce_index)
        return df

    def _collect_entity_names(self):
        """ Collect all entity-names in netbox."""
        df = self.entity_mib.retrieve_columns([
            'entPhysicalDescr',
            'entPhysicalName',
        ])
        df.addCallback(reduce_index)
        return df

    @defer.inlineCallbacks
    def get_all_sensors(self):
        """ Collect all sensors and names on a netbox, and match
            sensors with names.

            Return a list with dictionaries, each dictionary
            represent a sensor."""
        self._logger.debug('get_all_sensors: Called....')
        sensors = yield self._get_sensors()
        entity_names = yield self._collect_entity_names()
        for idx, row in entity_names.items():
            if idx in sensors:
                sensors[idx]['entPhysicalDescr'] = row.get(
                    'entPhysicalDescr', None)
                sensors[idx]['entPhysicalName'] = row.get(
                    'entPhysicalName', None)
        result = []
        for row_id, row in sensors.items():
            row_oid = row.get(0, None)
            mibobject = self.nodes.get('entSensorValue', None)
            oid = str(mibobject.oid) + str(row_oid)
            unit_of_measurement = row.get('entSensorType', 2)
            precision = row.get('entSensorPrecision', 0)
            scale = row.get('entSensorScale', None)
            op_status = row.get('entSensorStatus', None)
            description = row.get('entPhysicalDescr', None)
            name = row.get('entPhysicalName', None)
            internal_name = name
            if op_status == 1:
                result.append({
                    'oid':
                    oid,
                    'unit_of_measurement':
                    UNITS_OF_MEASUREMENTS.get(unit_of_measurement, None),
                    'precision':
                    precision,
                    'scale':
                    DATA_SCALE.get(scale, None),
                    'description':
                    description,
                    'name':
                    name,
                    'internal_name':
                    internal_name,
                    'mib':
                    self.get_module_name(),
                })
        self._logger.debug('get_all_sensors: result=%s' % str(result))
        defer.returnValue(result)
class CiscoEntitySensorMib(mibretriever.MibRetriever):
    """This MIB should collect all present sensors from Cisco NEXUS boxes."""
    from nav.smidumps.cisco_entity_sensor_mib import MIB as mib

    def __init__(self, agent_proxy):
        """Good old constructor..."""
        super(CiscoEntitySensorMib, self).__init__(agent_proxy)
        self.entity_mib = EntityMib(self.agent_proxy)

    def get_module_name(self):
        """Get the name of this MIB"""
        return self.mib.get('moduleName', None)

    def _get_sensors(self):
        """ Collect all sensors from the box."""
        df = self.retrieve_columns([
                'entSensorType',
                'entSensorScale',
                'entSensorPrecision',
                'entSensorValue',
                'entSensorStatus',
                'entSensorValueTimeStamp',
                'entSensorValueUpdateRate',
                'entSensorMeasuredEntity',
                ])
        df.addCallback(reduce_index)
        return df

    def _collect_entity_names(self):
        """ Collect all entity-names in netbox."""
        df = self.entity_mib.retrieve_columns([
                'entPhysicalDescr',
                'entPhysicalName',
                ])
        df.addCallback(reduce_index)
        return df

    @defer.inlineCallbacks
    def get_all_sensors(self):
        """ Collect all sensors and names on a netbox, and match
            sensors with names.

            Return a list with dictionaries, each dictionary
            represent a sensor."""
        self._logger.debug('get_all_sensors: Called....')
        sensors = yield self._get_sensors()
        entity_names = yield self._collect_entity_names()
        for idx, row in entity_names.items():
            if idx in sensors:
                sensors[idx]['entPhysicalDescr'] = row.get(
                    'entPhysicalDescr',None)
                sensors[idx]['entPhysicalName'] = row.get(
                    'entPhysicalName', None)
        result = []
        for row_id, row in sensors.items():
            row_oid = row.get(0, None)
            mibobject = self.nodes.get('entSensorValue', None)
            oid = str(mibobject.oid) + str(row_oid)
            unit_of_measurement = row.get('entSensorType', 2)
            precision = row.get('entSensorPrecision', 0)
            scale = row.get('entSensorScale', None)
            op_status = row.get('entSensorStatus', None)
            description = row.get('entPhysicalDescr', None)
            name = row.get('entPhysicalName', None)
            internal_name = name
            if op_status == 1:
                result.append({
                    'oid': oid,
                    'unit_of_measurement': UNITS_OF_MEASUREMENTS.get(
                        unit_of_measurement, None),
                    'precision': precision,
                    'scale': DATA_SCALE.get(scale, None),
                    'description': description,
                    'name': name,
                    'internal_name': internal_name,
                    'mib': self.get_module_name(),
                    })
        self._logger.debug('get_all_sensors: result=%s' % str(result))
        defer.returnValue(result)