def _handler(self, action):
        """
        Sets up an SNMP handler with the current SNMPHandler state

        :rtype: QualiSnmp
        """
        mib_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'mibs'))
        snmp_parameters = self._snmp_parameters(action)

        try:
            handler = QualiSnmp(snmp_parameters, self.logger)
        except Exception as e:
            if action.lower() == 'get':
                error = '''Unable to communicate via SNMP read to resource
                Please verify the SNMP read community and that the device is accessible'''
            elif action.lower() == 'set':
                error = '''Unable to communicate via SNMP write to resource
                Please verify the SNMP write community and that the device is accessible'''
            else:
                error = '''Unable to communicate via SNMP to resource
                Please verify the SNMP communities and that the device is accessible'''
            raise Exception(error + '\nDownstream error: ' + str(e))
        handler.update_mib_sources(mib_path)
        handler.load_mib(['Sentry3-MIB'])

        return handler
    def _get_handler(self, action):
        mib_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'mibs'))
        snmp_parameters = self._get_snmp_parameters(action)

        handler = QualiSnmp(snmp_parameters, self.logger)
        handler.update_mib_sources(mib_path)
        handler.load_mib(['Sentry3-MIB'])

        return handler
Example #3
0
def geist_autoload(context):
    logger = get_logger(context)
    snmp_parameters = get_snmp_parameters_from_command_context(context,
                                                               write=False)
    snmp = QualiSnmp(snmp_parameters, logger)
    path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', 'mibs'))
    snmp.update_mib_sources(path)
    snmp.load_mib(['GEIST-MIB-V3'])

    def makeres(name, model, relative_address, unique_identifier):
        r = AutoLoadResource()
        r.name = name
        r.model = model
        r.relative_address = relative_address
        r.unique_identifier = unique_identifier
        return r

    def makeattr(relative_address, attribute_name, attribute_value):
        a = AutoLoadAttribute()
        a.relative_address = relative_address
        a.attribute_name = attribute_name
        a.attribute_value = attribute_value
        return a

    rv = AutoLoadDetails()
    rv.resources = []
    rv.attributes = []

    rv.attributes.append(
        makeattr('', 'Version',
                 snmp.get_property('GEIST-MIB-V3', 'productVersion', 0)))
    rv.attributes.append(
        makeattr('', 'Location',
                 snmp.get_property('SNMPv2-MIB', 'sysLocation', 0)))
    rv.attributes.append(
        makeattr('', 'Vendor',
                 snmp.get_property('GEIST-MIB-V3', 'productHardware', 0)))
    rv.attributes.append(
        makeattr('', 'Model',
                 snmp.get_property('GEIST-MIB-V3', 'productTitle', 0)))

    pduname = snmp.get_property('GEIST-MIB-V3', 'productFriendlyName', 0)

    outlet_table = snmp.get_table('GEIST-MIB-V3', 'ctrlOutletTable')

    for idx, record in outlet_table.iteritems():
        addr = '%d' % idx
        rv.resources.append(
            makeres('Port %d' % idx, 'Generic Power Socket', addr,
                    '%s.%d' % (pduname, idx)))
        rv.attributes.append(
            makeattr(addr, 'Port Description', record['ctrlOutletName']))

    return rv
Example #4
0
def do_geist_power(context, f, portstr):
    logger = get_logger(context)
    snmp_parameters = get_snmp_parameters_from_command_context(context,
                                                               write=True)
    snmp = QualiSnmp(snmp_parameters, logger)
    path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..', 'mibs'))
    snmp.update_mib_sources(path)
    snmp.load_mib(['GEIST-MIB-V3'])
    logger.info('geist power called with port "%s"' % portstr)
    f(snmp, portstr)