예제 #1
0
def doAll(snmpClient, hostOSH, OSHVResult, ucmdbversion, Framework):

    vlanTableMib = '1.3.6.1.4.1.9.9.46.1.3.1.1.4,1.3.6.1.4.1.9.9.46.1.3.1.1.5,string'
    elanNameTableMib = '1.3.6.1.4.1.353.5.3.1.1.2.1.14,1.3.6.1.4.1.353.5.3.1.1.2.1.15,string'
    vlanNumberPerElanTableMib = '1.3.6.1.4.1.9.9.77.1.1.1.1.1,1.3.6.1.4.1.9.9.77.1.1.1.1.2,string'
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    snmp_version = Framework.getProtocolProperty(credentialsId,
                                                 "snmpprotocol_version")

    vlanTableRes = snmpClient.executeQuery(
        vlanTableMib)  #@@CMD_PERMISION snmp protocol execution
    elanNameTableRes = snmpClient.executeQuery(
        elanNameTableMib)  #@@CMD_PERMISION snmp protocol execution
    vlanNumberPerElanTableRes = snmpClient.executeQuery(
        vlanNumberPerElanTableMib)  #@@CMD_PERMISION snmp protocol execution

    vlanTable = vlanTableRes.asTable()
    elanNameTable = elanNameTableRes.asTable()
    vlanNumberPerElanTable = vlanNumberPerElanTableRes.asTable()

    if len(vlanTable) == 0:
        raise Exception, "No VLANs Configured on the device."

    vlan_context_dict = {}
    if snmp_version and snmp_version == 'version 3':
        vlan_context_dict = snmputils.get_snmp_vlan_context_dict(snmpClient)

    if snmpClient:
        snmpClient.close()

    for i in range(len(vlanTable)):
        vlanOid = vlanTable[i][0]
        vlanName = vlanTable[i][1]
        vlanNumberA = vlanOid[vlanOid.find('.') + 1:]

        vlanOSH = ObjectStateHolder('vlan')
        vlanOSH.setContainer(hostOSH)
        modeling.setVlanIdAttribute(vlanOSH, vlanNumberA)
        try:
            linkedPorts = discoverPorts(vlanNumberA, vlanOSH, hostOSH,
                                        ucmdbversion, Framework,
                                        vlan_context_dict)
        except ValueError:
            logger.debug(
                'No ports are assigned for VLAN %s, discarding port from result vector, Vlan will not be reported.'
                % vlanNumberA)
            continue
        except:
            logger.debug('Failed to discover ports for VLAN %s' % vlanNumberA)
            logger.debugException('')
            continue
        else:
            OSHVResult.addAll(linkedPorts)

        vlanOSH.setAttribute('data_name', vlanName)
        OSHVResult.add(vlanOSH)

        for j in range(len(elanNameTable)):
            elanIndexA = elanNameTable[j][0]
            elanName = elanNameTable[j][1]

            for k in range(len(vlanNumberPerElanTable)):
                elanIndexB = vlanNumberPerElanTable[k][0]
                vlanNumberB = vlanNumberPerElanTable[k][1]

                if (vlanNumberB == vlanNumberA) and (elanIndexB == elanIndexA):
                    vlanOSH.setAttribute('vlan_aliasname', elanName)

                    elanOSH = ObjectStateHolder('elan')
                    elanOSH.setAttribute('data_name', elanName)
                    OSHVResult.add(elanOSH)

                    elanvlanmap_link = modeling.createLinkOSH(
                        'elanvlanmap', elanOSH, vlanOSH)
                    OSHVResult.add(elanvlanmap_link)

                    bcastdomain_link = modeling.createLinkOSH(
                        'bcastdomain', hostOSH, elanOSH)
                    OSHVResult.add(bcastdomain_link)
        Framework.sendObjects(OSHVResult)
        Framework.flushObjects()
        logger.debug(
            'Vlan %s successfully discovered. Result vector contains %d objects.'
            % (vlanName, OSHVResult.size()))
        OSHVResult = ObjectStateHolderVector()
예제 #2
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ObjSHV = ObjectStateHolderVector()
    discInst = RunInstance()
    ipAddressList = Framework.getTriggerCIDataAsList('ip_address')
    credentialsList = Framework.getTriggerCIDataAsList('credentialsId')
    bridgeId = Framework.getDestinationAttribute('bridgeId')
    hostIdList = Framework.getTriggerCIDataAsList('hostId')
    ucmdbVersion = modeling.CmdbClassModel().version()
    
    
    snmpCommunityPostfix = ''
    try:
        snmpCommunityPostfix = Framework.getDestinationAttribute('snmpCommunityPostfix')
        hostModel = Framework.getDestinationAttribute('hostModel')
        hostOs = Framework.getDestinationAttribute('hostOs')
        snmpDescription = Framework.getDestinationAttribute('smpDescription')
    except:
        pass

    SwitchesNumber = len(credentialsList)
    for i in range(SwitchesNumber):
        ipAddress = ipAddressList[i]
        hostId = hostIdList[i]
        credId = credentialsList[i]
        
        properties = Properties()

        if credId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credId)
        sw = Switch(bridgeId, hostId, ucmdbVersion, Framework)
        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            device_type_str = '%s%s%s' % (hostModel.lower(),
                                          hostOs.lower(),
                                          snmpDescription.lower())
            if device_type_str.find('atalyst')!=-1 or device_type_str.find('cisco')!=-1:
                snmp_version = Framework.getProtocolProperty(credId, "snmpprotocol_version")
                if snmp_version == 'version 3':
                    props = Properties()
                    props.setProperty('ip_address', ipAddress)
                    props.setProperty(BaseClient.CREDENTIALS_ID, credId)
                    client = Framework.createClient(props)
                    vlan_context_dict = snmputils.get_snmp_vlan_context_dict(client)
                    client and client.close()

                    if not vlan_context_dict:
                        raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"
                    
                    vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                    if not vlan_context:
                        raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix
                    
                    properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)
                else:
                    properties.setProperty(SnmpQueries._postfix,'@%s' % snmpCommunityPostfix)
            else:
                sw = QBridgeSwitch(snmpCommunityPostfix, bridgeId, hostId, ucmdbVersion, Framework)
                sw.set_device_type_str(device_type_str)
        if logger.isDebugEnabled():
            logger.debug('ip', ipAddress)
            logger.debug('bridgeMac', bridgeId)
            logger.debug('Postfix', snmpCommunityPostfix)

        try:
            sw.snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(sw.snmpClient).testSnmpConnection()
            sw.doWork(ObjSHV, discInst)
            OSHVResult.addAll(ObjSHV)
        except:
            logger.debugException('')
            if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
                logger.error('Failed to discover ip: ', ipAddress, ' on Vlan#: ', snmpCommunityPostfix)
            else:
                logger.error('Failed to discover ip: ', ipAddress )
        if sw.snmpClient != None:
            sw.snmpClient.close()
    return OSHVResult
예제 #3
0
def DiscoveryMain(Framework):

    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    ucmdbversion = modeling.CmdbClassModel().version()
    
    snmpCommunityPostfixList = ''
    try:
        snmpCommunityPostfixList = Framework.getTriggerCIDataAsList('snmpCommunityPostfix')
        if not snmpCommunityPostfixList:
            raise Exception, "No Vlans defined on switch"
    except:
        Framework.reportError('Failed to discover destination. No Vlans properly configured.')
        return OSHVResult

    hostId    = Framework.getDestinationAttribute('hostId')
    hostOSH = modeling.createOshByCmdbIdString('host', hostId)
    
    vlan_context_dict = {}
    snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version")
    if snmp_version == 'version 3':
        client = Framework.createClient()
        vlan_context_dict = snmputils.get_snmp_vlan_context_dict(client)
        client and client.close()
        
    vlanOSH = None
    failedToDiscoverCounter = 0
    for snmpCommunityPostfix in snmpCommunityPostfixList:
        vlanOSH = modeling.createVlanOsh(snmpCommunityPostfix, hostOSH)
        vlanOSH.setContainer(hostOSH)

        properties = Properties()
        if credentialsId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credentialsId)

        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            if snmp_version == 'version 3':
                if not vlan_context_dict:
                    logger.warn("Vlan Conext is not present on the device. No Vlan details might be discovered")
                    continue
                
                vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                if not vlan_context:
                    logger.warn("Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix)
                    continue
                properties.setProperty(SnmpQueries._postfix, '%s' % vlan_context)
            else:
                properties.setProperty(SnmpQueries._postfix, '%s%s' % ('@', snmpCommunityPostfix))
        

        snmpClient = None
        try:
            snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(snmpClient).testSnmpConnection()
            doAll(snmpClient, hostOSH, vlanOSH, OSHVResult, ucmdbversion)
            Framework.sendObjects(OSHVResult)
            Framework.flushObjects()
            logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (snmpCommunityPostfix, OSHVResult.size()))
            OSHVResult = ObjectStateHolderVector()
        except:
            logger.debugException('')
            failedToDiscoverCounter =+ 1
            logger.debugException('Failed to discover ip: %s on Vlan#: %s. ' % (ipAddress, snmpCommunityPostfix))
        if snmpClient != None:
            snmpClient.close()

    if failedToDiscoverCounter == len(snmpCommunityPostfixList):
        Framework.reportError('Failed to discover all Vlans on the destination.')
    elif failedToDiscoverCounter:
        Framework.reportWarning('Failed to discover one or more Vlans on the destination')
    
    if snmpClient != None:
        snmpClient.close()
    return OSHVResult
def doAll(snmpClient ,hostOSH, OSHVResult, ucmdbversion, Framework):

    vlanTableMib            = '1.3.6.1.4.1.9.9.46.1.3.1.1.4,1.3.6.1.4.1.9.9.46.1.3.1.1.5,string'
    elanNameTableMib        = '1.3.6.1.4.1.353.5.3.1.1.2.1.14,1.3.6.1.4.1.353.5.3.1.1.2.1.15,string'
    vlanNumberPerElanTableMib    = '1.3.6.1.4.1.9.9.77.1.1.1.1.1,1.3.6.1.4.1.9.9.77.1.1.1.1.2,string'
    credentialsId = Framework.getDestinationAttribute('credentialsId')
    snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version")
    
    vlanTableRes = snmpClient.executeQuery(vlanTableMib)#@@CMD_PERMISION snmp protocol execution
    elanNameTableRes = snmpClient.executeQuery(elanNameTableMib)#@@CMD_PERMISION snmp protocol execution
    vlanNumberPerElanTableRes = snmpClient.executeQuery(vlanNumberPerElanTableMib)#@@CMD_PERMISION snmp protocol execution
    
    vlanTable = vlanTableRes.asTable()
    elanNameTable = elanNameTableRes.asTable()
    vlanNumberPerElanTable = vlanNumberPerElanTableRes.asTable()
    
    
    if len(vlanTable) == 0:
        raise Exception, "No VLANs Configured on the device."
    
    vlan_context_dict = {}
    if snmp_version and snmp_version == 'version 3':
        vlan_context_dict = snmputils.get_snmp_vlan_context_dict(snmpClient)
        
    if snmpClient:
        snmpClient.close()

    for i in range(len(vlanTable)):
        vlanOid = vlanTable[i][0]
        vlanName = vlanTable[i][1]
        vlanNumberA = vlanOid[vlanOid.find('.')+1:]

        vlanOSH = ObjectStateHolder('vlan')
        vlanOSH.setContainer(hostOSH)
        modeling.setVlanIdAttribute(vlanOSH, vlanNumberA)
        try:
            linkedPorts = discoverPorts(vlanNumberA, vlanOSH, hostOSH, ucmdbversion, Framework, vlan_context_dict)
        except ValueError:
            logger.debug('No ports are assigned for VLAN %s, discarding port from result vector, Vlan will not be reported.' % vlanNumberA)
            continue
        except:
            logger.debug('Failed to discover ports for VLAN %s' % vlanNumberA)
            logger.debugException('')
            continue
        else:
            OSHVResult.addAll(linkedPorts)

        vlanOSH.setAttribute('data_name', vlanName)
        OSHVResult.add(vlanOSH)

        for j in range(len(elanNameTable)):
            elanIndexA = elanNameTable[j][0]
            elanName = elanNameTable[j][1]

            for k in range(len(vlanNumberPerElanTable)):
                elanIndexB = vlanNumberPerElanTable[k][0]
                vlanNumberB = vlanNumberPerElanTable[k][1]

                if (vlanNumberB == vlanNumberA) and (elanIndexB == elanIndexA):
                    vlanOSH.setAttribute('vlan_aliasname', elanName)

                    elanOSH = ObjectStateHolder('elan')
                    elanOSH.setAttribute('data_name', elanName)
                    OSHVResult.add(elanOSH)
                    
                    elanvlanmap_link = modeling.createLinkOSH('elanvlanmap',elanOSH,vlanOSH)
                    OSHVResult.add(elanvlanmap_link)
                    
                    bcastdomain_link = modeling.createLinkOSH('bcastdomain',hostOSH, elanOSH)
                    OSHVResult.add(bcastdomain_link)
        Framework.sendObjects(OSHVResult)
        Framework.flushObjects()
        logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (vlanName, OSHVResult.size()))
        OSHVResult = ObjectStateHolderVector()
예제 #5
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ObjSHV = ObjectStateHolderVector()
    discInst = RunInstance()
    ipAddressList = Framework.getTriggerCIDataAsList('ip_address')
    credentialsList = Framework.getTriggerCIDataAsList('credentialsId')
    bridgeId = Framework.getDestinationAttribute('bridgeId')
    hostIdList = Framework.getTriggerCIDataAsList('hostId')
    ucmdbVersion = modeling.CmdbClassModel().version()

    snmpCommunityPostfix = ''
    try:
        snmpCommunityPostfix = Framework.getDestinationAttribute(
            'snmpCommunityPostfix')
        hostModel = Framework.getDestinationAttribute('hostModel')
        hostOs = Framework.getDestinationAttribute('hostOs')
        snmpDescription = Framework.getDestinationAttribute('smpDescription')
    except:
        pass

    SwitchesNumber = len(credentialsList)
    for i in range(SwitchesNumber):
        ipAddress = ipAddressList[i]
        hostId = hostIdList[i]
        credId = credentialsList[i]

        properties = Properties()

        if credId and ipAddress:
            properties.setProperty('ip_address', ipAddress)
            properties.setProperty(BaseClient.CREDENTIALS_ID, credId)
        sw = Switch(bridgeId, hostId, ucmdbVersion, Framework)
        if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
            device_type_str = '%s%s%s' % (hostModel.lower(), hostOs.lower(),
                                          snmpDescription.lower())
            if device_type_str.find('atalyst') != -1 or device_type_str.find(
                    'cisco') != -1:
                snmp_version = Framework.getProtocolProperty(
                    credId, "snmpprotocol_version")
                if snmp_version == 'version 3':
                    props = Properties()
                    props.setProperty('ip_address', ipAddress)
                    props.setProperty(BaseClient.CREDENTIALS_ID, credId)
                    client = Framework.createClient(props)
                    vlan_context_dict = snmputils.get_snmp_vlan_context_dict(
                        client)
                    client and client.close()

                    if not vlan_context_dict:
                        raise Exception, "Vlan Conext is not present on the device. No Vlan details might be discovered"

                    vlan_context = vlan_context_dict.get(snmpCommunityPostfix)
                    if not vlan_context:
                        raise Exception, "Failed to find configured Vlan context for Vlan %s. Vlan will be skipped" % snmpCommunityPostfix

                    properties.setProperty(SnmpQueries._postfix,
                                           '%s' % vlan_context)
                else:
                    properties.setProperty(SnmpQueries._postfix,
                                           '@%s' % snmpCommunityPostfix)
            else:
                sw = QBridgeSwitch(snmpCommunityPostfix, bridgeId, hostId,
                                   ucmdbVersion, Framework)
                sw.set_device_type_str(device_type_str)
        if logger.isDebugEnabled():
            logger.debug('ip', ipAddress)
            logger.debug('bridgeMac', bridgeId)
            logger.debug('Postfix', snmpCommunityPostfix)

        try:
            sw.snmpClient = Framework.createClient(properties)
            #SnmpConnectionTester(sw.snmpClient).testSnmpConnection()
            sw.doWork(ObjSHV, discInst)
            OSHVResult.addAll(ObjSHV)
        except:
            logger.debugException('')
            if (snmpCommunityPostfix != None) and (snmpCommunityPostfix != ''):
                logger.error('Failed to discover ip: ', ipAddress,
                             ' on Vlan#: ', snmpCommunityPostfix)
            else:
                logger.error('Failed to discover ip: ', ipAddress)
        if sw.snmpClient != None:
            sw.snmpClient.close()
    return OSHVResult