def __get_snmp_handler(self, host, logger):
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__), ".", "mibs"))
     logger.info(host)
     logger.info(self._snmp_write_community)
     if "3" in self._snmp_version:
         if not self._snmp_v3_user or not self._snmp_v3_password or not self._snmp_v3_private_key:
             raise Exception(
                 self.__class__.__name__,
                 "Cannot create SNMP Version 3, Check configuration")
         snmp_params = SNMPV3Parameters(
             ip=host,
             snmp_user=self._snmp_v3_user,
             snmp_password=self._snmp_v3_password,
             snmp_private_key=self._snmp_v3_private_key)
         logger.info("SNMP V3 Created")
     else:
         if not self._snmp_write_community:
             raise Exception(
                 self.__class__.__name__,
                 "Cannot create SNMP Version 2, Check configuration")
         snmp_params = SNMPV2Parameters(
             ip=host, snmp_community=self._snmp_write_community)
         logger.info("SNMP V2 Created")
     snmp_handler = QualiSnmp(snmp_params, logger)
     snmp_handler.update_mib_sources(path)
     return snmp_handler
    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
Esempio n. 4
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
Esempio n. 5
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)