コード例 #1
0
    def discoverVirtualServers(self, cisco_ace):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_VSERVER)
        queryBuilder.addQueryElement(1, 'Vserver_name')
        queryBuilder.addQueryElement(4, 'ipAddress')
        queryBuilder.addQueryElement(5, 'port')
        queryBuilder.addQueryElement(9, 'farmName')
        virtualServers = self.snmpAgent.getSnmpData(queryBuilder)

        farmNameToVirtualServer = {}
        for virtualServer in virtualServers:
            virtualServerHelper = VirtualServerHelper(
                virtualServer.Vserver_name, virtualServer.ipAddress, cisco_ace,
                virtualServer.port)
            farmNameToVirtualServer[
                virtualServer.farmName] = virtualServerHelper

        self.discoverFarms(farmNameToVirtualServer, cisco_ace)

        for virtualServerHelper in farmNameToVirtualServer.values():
            if virtualServerHelper.hasAtLeastOneParentCluster():
                virtualServerHelper.addResultsToVector(self.OSHVResult)
            else:
                logger.debug(
                    "Virtual server %s was not reported since it is not linked to any cluster"
                    % virtualServerHelper)
コード例 #2
0
def createCssDiscoverer(snmpClient, Framework, OSHVResult, hostOsh):
	for cssOidBase in CSS_OID_BASES:
		snmpAgent = SnmpAgent(cssOidBase, snmpClient, Framework)
		queryProducer = SnmpQueryBuilder(TEST_OID_OFFSET)
		queryProducer.addQueryElement(2, 'test')
		testResults = snmpAgent.getSnmpData(queryProducer)
		
		if len(testResults):
			return CssDiscoverer(snmpAgent, OSHVResult, Framework, hostOsh)
		
	raise NoCssException
コード例 #3
0
def createCssDiscoverer(snmpClient, Framework, OSHVResult, hostOsh):
    for cssOidBase in CSS_OID_BASES:
        snmpAgent = SnmpAgent(cssOidBase, snmpClient, Framework)
        queryProducer = SnmpQueryBuilder(TEST_OID_OFFSET)
        queryProducer.addQueryElement(2, 'test')
        testResults = snmpAgent.getSnmpData(queryProducer)

        if len(testResults):
            return CssDiscoverer(snmpAgent, OSHVResult, Framework, hostOsh)

    raise NoCssException
コード例 #4
0
    def discoverVirtualServers(self, alteon):
        queryBuilder = SnmpQueryBuilder(VIRTUAL_SERVERS)
        queryBuilder.addQueryElement(1, "index")
        queryBuilder.addQueryElement(2, "ipAddress")

        virtualServers = self.snmpAgent.getSnmpData(queryBuilder)

        virtualServerIndexToIpMap = {}
        for virtualServer in virtualServers:
            virtualServerIndexToIpMap[virtualServer.index] = virtualServer.ipAddress

        self.discoverVirtualServices(virtualServerIndexToIpMap, alteon)
コード例 #5
0
 def discoverRealServers(self):
     queryBuilder = SnmpQueryBuilder(REAL_SERVERS)
     queryBuilder.addQueryElement(1, "index")
     queryBuilder.addQueryElement(2, "ipAddress")
     realServers = self.snmpAgent.getSnmpData(queryBuilder)
     serverList = {}
     for realServer in realServers:
         ipAddress = realServer.ipAddress.strip()
         index = int(realServer.index.strip())
         hostOsh = modeling.createHostOSH(ipAddress)
         realServer = RealServer(ipAddress, hostOsh)
         serverList[index] = realServer
         self.OSHVResult.add(hostOsh)
     return serverList
コード例 #6
0
 def discoverPortLinks(self):
     queryBuilder = SnmpQueryBuilder(PORT_LINKS)
     queryBuilder.addQueryElement(1, 'realServerIndex')
     queryBuilder.addQueryElement(2, 'portIndex')
     queryBuilder.addQueryElement(3, 'port')
     
     portLinks = self.snmpAgent.getSnmpData(queryBuilder)
     for portLink in portLinks:
         portMapping = self.getPortMapping(portLink.realServerIndex)
         portMapping.addPort(portLink.port)
コード例 #7
0
 def discoverVirtualServers(self, f5):
     queryBuilder = SnmpQueryBuilder('3.2.1')
     queryBuilder.addQueryElement(1, 'ipAddress')    
     queryBuilder.addQueryElement(2, 'port')
     queryBuilder.addQueryElement(29, 'rule')
     queryBuilder.addQueryElement(30, 'poolName')
     virtualServers = self.snmpAgent.getSnmpData(queryBuilder)
     
     poolNameToVirtualServer = {}
     for virtualServer in virtualServers:
         virtualServerHelper = VirtualServerHelper(None, virtualServer.ipAddress, f5, virtualServer.port)
         poolNameToVirtualServer[virtualServer.poolName] = virtualServerHelper
     
     self.discoverPools(poolNameToVirtualServer, f5)
     
     for virtualServerHelper in poolNameToVirtualServer.values():
         if virtualServerHelper.hasAtLeastOneParentCluster():
             virtualServerHelper.addResultsToVector(self.OSHVResult)
コード例 #8
0
 def discoverPools(self, poolNameToVirtualServer, f5):
     queryBuilder = SnmpQueryBuilder('7.2.1')
     queryBuilder.addQueryElement(1, 'name')
     pools = self.snmpAgent.getSnmpData(queryBuilder)
     
     poolNameToPool = {}
     for pool in pools:
         poolOsh = ObjectStateHolder('loadbalancecluster')
         poolOsh.setAttribute('data_name', pool.name)
         memberLink = modeling.createLinkOSH('membership', f5, poolOsh)
         self.OSHVResult.add(memberLink)
         poolNameToPool[pool.name] = poolOsh
         self.OSHVResult.add(poolOsh)
         if poolNameToVirtualServer.has_key(pool.name):
             virtualServerHelper = poolNameToVirtualServer[pool.name]
             virtualServerHelper.linkToContainingCluster(poolOsh, pool.name)
         else:
             logger.debug('Pool %s is not related to any virtual server.' % pool.name)
         
     self.discoverPoolMembers(poolNameToPool)
コード例 #9
0
    def discoverPortLinks(self):
        queryBuilder = SnmpQueryBuilder(PORT_LINKS)
        queryBuilder.addQueryElement(1, "realServerIndex")
        queryBuilder.addQueryElement(2, "portIndex")
        queryBuilder.addQueryElement(3, "port")

        portLinks = self.snmpAgent.getSnmpData(queryBuilder)
        for portLink in portLinks:
            portMapping = self.getPortMapping(portLink.realServerIndex)
            portMapping.addPort(portLink.port)
コード例 #10
0
    def discoverFarms(self, farmNameToVirtualServer, cisco_ace):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_FARM)
        queryBuilder.addQueryElement(1, 'name')
        farms = self.snmpAgent.getSnmpData(queryBuilder)

        farmNameToFarm = {}
        for farm in farms:
            farmOsh = ObjectStateHolder('loadbalancecluster')
            farmOsh.setAttribute('data_name', farm.name)
            self.OSHVResult.add(farmOsh)
            memberLink = modeling.createLinkOSH('membership', farmOsh, cisco_ace)
            self.OSHVResult.add(memberLink)
            farmNameToFarm[farm.name] = farmOsh
            self.OSHVResult.add(farmOsh)
            if farmNameToVirtualServer.has_key(farm.name):
                virtualServerHelper = farmNameToVirtualServer[farm.name]
                virtualServerHelper.linkToContainingCluster(farmOsh, farm.name)
            else:
                logger.debug('Farm %s is not related to any virtual server.' % farm.name)

        self.discoverFarmMembers(farmNameToFarm)
コード例 #11
0
    def discoverGroupMembers(self, serverNameToGroup):
        queryBuilder = SnmpQueryBuilder(A10_OID_TABLE_SERVER)
        queryBuilder.addQueryElement(1, 'server_name')
        queryBuilder.addQueryElement(3, 'port')
        queryBuilder.addQueryElement(4, 'ipAddress')
        groupMembers = self.snmpAgent.getSnmpData(queryBuilder)

        for groupMember in groupMembers:
            groupMemberOsh = modeling.createHostOSH(groupMember.ipAddress, 'host')
            serviceAddressOsh = modeling.createServiceAddressOsh(groupMemberOsh, groupMember.ipAddress,
                                                                 groupMember.port, modeling.SERVICEADDRESS_TYPE_TCP)
            self.OSHVResult.add(groupMemberOsh)
            self.OSHVResult.add(serviceAddressOsh)
            groupOsh = serverNameToGroup[groupMember.server_name]
            self.OSHVResult.add(modeling.createLinkOSH('member', groupOsh, serviceAddressOsh))
コード例 #12
0
 def discoverPoolMembers(self, poolNameToPool):
     queryBuilder = SnmpQueryBuilder('8.2.1')        
     queryBuilder.addQueryElement(1, 'poolName')
     queryBuilder.addQueryElement(2, 'ipAddress')
     queryBuilder.addQueryElement(3, 'port')
     poolMembers = self.snmpAgent.getSnmpData(queryBuilder)
     
     for poolMember in poolMembers:
         poolMemberOsh = modeling.createHostOSH(poolMember.ipAddress, 'host')
         serviceAddressOsh = modeling.createServiceAddressOsh(poolMemberOsh, poolMember.ipAddress,
                                                              poolMember.port, modeling.SERVICEADDRESS_TYPE_TCP)
         self.OSHVResult.add(poolMemberOsh)
         self.OSHVResult.add(serviceAddressOsh)
         poolOsh = poolNameToPool[poolMember.poolName]
         self.OSHVResult.add(modeling.createLinkOSH('member', poolOsh, serviceAddressOsh))
コード例 #13
0
    def discoverFarms(self, farmNameToVirtualServer, cisco_ace):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_FARM)
        queryBuilder.addQueryElement(1, 'name')
        farms = self.snmpAgent.getSnmpData(queryBuilder)

        farmNameToFarm = {}
        for farm in farms:
            farmOsh = ObjectStateHolder('loadbalancecluster')
            farmOsh.setAttribute('data_name', farm.name)
            self.OSHVResult.add(farmOsh)
            memberLink = modeling.createLinkOSH('membership', farmOsh,
                                                cisco_ace)
            self.OSHVResult.add(memberLink)
            farmNameToFarm[farm.name] = farmOsh
            self.OSHVResult.add(farmOsh)
            if farmNameToVirtualServer.has_key(farm.name):
                virtualServerHelper = farmNameToVirtualServer[farm.name]
                virtualServerHelper.linkToContainingCluster(farmOsh, farm.name)
            else:
                logger.debug('Farm %s is not related to any virtual server.' %
                             farm.name)

        self.discoverFarmMembers(farmNameToFarm)
コード例 #14
0
    def discoverVirtualServers(self, cisco_ace):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_VSERVER)
        queryBuilder.addQueryElement(1, 'Vserver_name')
        queryBuilder.addQueryElement(4, 'ipAddress')
        queryBuilder.addQueryElement(5, 'port')
        queryBuilder.addQueryElement(9, 'farmName')
        virtualServers = self.snmpAgent.getSnmpData(queryBuilder)

        farmNameToVirtualServer = {}
        for virtualServer in virtualServers:
            virtualServerHelper = VirtualServerHelper(virtualServer.Vserver_name, virtualServer.ipAddress, cisco_ace, virtualServer.port)
            farmNameToVirtualServer[virtualServer.farmName] = virtualServerHelper

        self.discoverFarms(farmNameToVirtualServer, cisco_ace)

        for virtualServerHelper in farmNameToVirtualServer.values():
            if virtualServerHelper.hasAtLeastOneParentCluster():
                virtualServerHelper.addResultsToVector(self.OSHVResult)
            else:
                logger.debug("Virtual server %s was not reported since it is not linked to any cluster" % virtualServerHelper)
コード例 #15
0
    def discoverF5(self, f5Osh):
        queryBuilder = SnmpQueryBuilder('1.1')
        queryBuilder.addQueryElement(1, 'kernel')
        queryBuilder.addQueryElement(2, 'package')
        queryBuilder.addQueryElement(3, 'edition')
        queryBuilder.addQueryElement(4, 'agent')
        
        try:
            versionInformation = self.snmpAgent.getSnmpData(queryBuilder)[0]        
            f5Osh.setAttribute('application_version', versionInformation.kernel)
        except:
            errorMsg = 'Failed to get general information'
            errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg)
            logger.debugException(errorMsg)
            logger.reportWarningObject(errobj)

        self.discoverVirtualServers(f5Osh)
コード例 #16
0
 def discoverPoolMembers(self, nameToPool):
     queryBuilder = SnmpQueryBuilder('5.3.2.1')
     queryBuilder.addQueryElement(1, 'poolName')
     queryBuilder.addQueryElement(2, 'addressType')
     queryBuilder.addQueryElement(3, 'address', 'hexa')
     queryBuilder.addQueryElement(4, 'port')
     poolMembers = self.snmpAgent.getSnmpData(queryBuilder)
     
     for poolMember in poolMembers:
         ipAddress = self.convertToIp(poolMember.address)
         hostOsh = modeling.createHostOSH(ipAddress, 'host')
         serviceAddressOsh = modeling.createServiceAddressOsh(hostOsh, ipAddress,
                                                             poolMember.port, modeling.SERVICEADDRESS_TYPE_TCP)
         try:
             #TODO: consider about avoiding try-except here
             self.add(modeling.createLinkOSH('member', nameToPool[poolMember.poolName], serviceAddressOsh)) 
             self.add(hostOsh)
             self.add(serviceAddressOsh)
         except:
             errorMsg = 'Failed to link %s member with pool %s' % (ipAddress, poolMember.poolName)
             errobj = errorobject.createError(errorcodes.FAILED_LINKING_ELEMENTS, ['%s member' % ipAddress, 'pool %s' % poolMember.poolName], errorMsg)
             #TODO: Change log level to debug
             logger.debugException('errorMsg')
             logger.reportWarningObject(errobj)
コード例 #17
0
    def discoverRealGroups(self, realGroupIndexToVirtualServer):
        queryBuilder = SnmpQueryBuilder(REAL_GROUPS)
        queryBuilder.addQueryElement(1, 'index', 'int')
        queryBuilder.addQueryElement(2, 'realServers', 'hexa')
        queryBuilder.addQueryElement(8, 'groupName')

        realGroups = self.snmpAgent.getSnmpData(queryBuilder)
        serverList = self.discoverRealServers()
        self.discoverPortLinks()
        for realGroup in realGroups:
            cluster = ObjectStateHolder('loadbalancecluster')
            dataName = realGroup.groupName
            index = realGroup.index.strip()
                        
            if not dataName:
                dataName = index
            cluster.setAttribute('data_name', dataName)
            self.OSHVResult.add(cluster)
            realPort = None
            if realGroupIndexToVirtualServer.has_key(index):
                virtualServerWrapper = realGroupIndexToVirtualServer[index]
                virtualServerWrapper.addResultsToVector(self.OSHVResult, cluster)
                realPort = realGroupIndexToVirtualServer[index].realPort
            else:
                logger.warn('Alteon real group index %s taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.3.3.1.1 does not match any virtual service\'s real group index taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.4.5.1' % index)
                errobj = errorobject.createError(errorcodes.FAILED_LINKING_ELEMENTS, ['real group %s' % dataName, 'virtual service'], 'Failed to link real group %s to virtual service' % dataName)
                logger.reportWarningObject(errobj)
                
            realServerNumbers = parseMappingString(realGroup.realServers.strip())
            #reporting real ports from Virtual service table for each real server:
            for realServer in realServerNumbers:
                if serverList.has_key(realServer):
                    if realPort:
                        serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), realPort, modeling.SERVICEADDRESS_TYPE_TCP)
                        self.OSHVResult.add(serviceAddress)
                        self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress))
                    elif self.portMappings.has_key(realServer):
                        portMapping = self.getPortMapping(realServerindex)
                        for port in portMapping.getPorts():
                            serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), port, modeling.SERVICEADDRESS_TYPE_TCP)
                            self.OSHVResult.add(serviceAddress)
                            self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress))
                    else:
                        serviceAddress = modeling.createServiceAddressOsh(serverList[realServer].getServer(), serverList[realServer].getIPAddress(), 0, modeling.SERVICEADDRESS_TYPE_TCP, 'unknown')
                        self.OSHVResult.add(serviceAddress)
                        self.OSHVResult.add(modeling.createLinkOSH('member', cluster, serviceAddress))
コード例 #18
0
    def discoverFarmMembers(self, farmNameToFarm):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_SERVER)
        queryBuilder.addQueryElement(1, 'farmName')
        queryBuilder.addQueryElement(2, 'ipAddress')
        queryBuilder.addQueryElement(3, 'port')
        farmMembers = self.snmpAgent.getSnmpData(queryBuilder)

        for farmMember in farmMembers:
            farmMemberOsh = modeling.createHostOSH(farmMember.ipAddress,
                                                   'host')
            serviceAddressOsh = modeling.createServiceAddressOsh(
                farmMemberOsh, farmMember.ipAddress, farmMember.port,
                modeling.SERVICEADDRESS_TYPE_TCP)
            self.OSHVResult.add(farmMemberOsh)
            self.OSHVResult.add(serviceAddressOsh)
            farmOsh = farmNameToFarm[farmMember.farmName]
            self.OSHVResult.add(
                modeling.createLinkOSH('member', farmOsh, serviceAddressOsh))
コード例 #19
0
    def discoverFarmMembers(self, farmNameToFarm):
        queryBuilder = SnmpQueryBuilder(CISCO_ACE_OID_TABLE_SERVER)
        queryBuilder.addQueryElement(1, 'farmName')
        queryBuilder.addQueryElement(2, 'ipAddress')
        queryBuilder.addQueryElement(3, 'port')
        farmMembers = self.snmpAgent.getSnmpData(queryBuilder)

        for farmMember in farmMembers:
            farmMemberOsh = modeling.createHostOSH(farmMember.ipAddress, 'host')
            serviceAddressOsh = modeling.createServiceAddressOsh(farmMemberOsh, farmMember.ipAddress,
                                                                 farmMember.port, modeling.SERVICEADDRESS_TYPE_TCP)
            self.OSHVResult.add(farmMemberOsh)
            self.OSHVResult.add(serviceAddressOsh)
            farmOsh = farmNameToFarm[farmMember.farmName]
            self.OSHVResult.add(modeling.createLinkOSH('member', farmOsh, serviceAddressOsh))
コード例 #20
0
 def discoverVirtualServers(self, alteon):
     queryBuilder = SnmpQueryBuilder(VIRTUAL_SERVERS)
     queryBuilder.addQueryElement(1, 'index')
     queryBuilder.addQueryElement(2, 'ipAddress')        
     
     virtualServers = self.snmpAgent.getSnmpData(queryBuilder)
             
     virtualServerIndexToIpMap = {}
     for virtualServer in virtualServers:
         virtualServerIndexToIpMap[virtualServer.index] = virtualServer.ipAddress
         
     self.discoverVirtualServices(virtualServerIndexToIpMap, alteon)
コード例 #21
0
    def discoverVirtualServers(self, a10_vthunder):
        queryBuilder = SnmpQueryBuilder(A10_OID_TABLE_VSERVER)
        queryBuilder.addQueryElement(1, 'Vserver_name')
        queryBuilder.addQueryElement(3, 'port')
        queryBuilder.addQueryElement(4, 'ipAddress')
        queryBuilder.addQueryElement(6, 'groupName')
        virtualServers = self.snmpAgent.getSnmpData(queryBuilder)

        groupNameToVirtualServer = {}
        for virtualServer in virtualServers:
            virtualServerHelper = VirtualServerHelper(virtualServer.Vserver_name, virtualServer.ipAddress, a10_vthunder, virtualServer.port)
            groupNameToVirtualServer[virtualServer.groupName] = virtualServerHelper

        self.discoverGroups(groupNameToVirtualServer, a10_vthunder)

        for virtualServerHelper in groupNameToVirtualServer.values():
            if virtualServerHelper.hasAtLeastOneParentCluster():
                virtualServerHelper.addResultsToVector(self.OSHVResult)
            else:
                logger.debug("Virtual server %s was not reported since it is not linked to any cluster" % virtualServerHelper)
コード例 #22
0
 def discoverRealServers(self):
     queryBuilder = SnmpQueryBuilder(REAL_SERVERS)
     queryBuilder.addQueryElement(1, 'index')
     queryBuilder.addQueryElement(2, 'ipAddress')
     realServers = self.snmpAgent.getSnmpData(queryBuilder)
     serverList = {}
     for realServer in realServers:
         ipAddress = realServer.ipAddress.strip()
         index = int(realServer.index.strip())
         hostOsh = modeling.createHostOSH(ipAddress)
         realServer = RealServer(ipAddress, hostOsh)
         serverList[index] = realServer
         self.OSHVResult.add(hostOsh)
     return serverList
コード例 #23
0
    def discoverA10_vthunder(self, a10_vthunder):
        queryBuilder = SnmpQueryBuilder(A10_OID_SYS)
        queryBuilder.addQueryElement(1, 'PrimaryVersion')
        queryBuilder.addQueryElement(2, 'SecondaryVersion')
        try:
            versionInformation = self.snmpAgent.getSnmpData(queryBuilder)[0]
            a10_vthunder.setAttribute('application_version', versionInformation.PrimaryVersion)
        except:
            errorMsg = 'Failed to get general information'
            errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg)
            logger.debugException(errorMsg)
            logger.reportWarningObject(errobj)

        self.discoverVirtualServers(a10_vthunder)
コード例 #24
0
    def discoverGroups(self, groupNameToVirtualServer, a10_vthunder):
        queryBuilder = SnmpQueryBuilder(A10_OID_TABLE_GROUP)
        queryBuilder.addQueryElement(1, 'name')
        queryBuilder.addQueryElement(3, 'server_name')
        groups = self.snmpAgent.getSnmpData(queryBuilder)

        serverNameToGroup = {}
        for group in groups:
            groupOsh = ObjectStateHolder('loadbalancecluster')
            groupOsh.setAttribute('data_name', group.name)
            self.OSHVResult.add(groupOsh)
            memberLink = modeling.createLinkOSH('membership', groupOsh, a10_vthunder)
            self.OSHVResult.add(memberLink)
            serverNameToGroup[group.server_name] = groupOsh
            self.OSHVResult.add(groupOsh)
            if groupNameToVirtualServer.has_key(group.name):
                virtualServerHelper = groupNameToVirtualServer[group.name]
                virtualServerHelper.linkToContainingCluster(groupOsh, group.name)
            else:
                logger.debug('Group %s is not related to any virtual server.' % group.name)

        self.discoverGroupMembers(serverNameToGroup)
コード例 #25
0
    def discoverServices(self):
        serviceQueryBuilder = SnmpQueryBuilder(SVC_OID_OFFSET)
        serviceQueryBuilder.addQueryElement(1, 'svc_name')
        serviceQueryBuilder.addQueryElement(3, 'ip')
        serviceQueryBuilder.addQueryElement(4, 'protocol')
        serviceQueryBuilder.addQueryElement(5, 'port')
        serviceQueryBuilder.addQueryElement(41, 'ip_range')
        serviceQueryBuilder.addQueryElement(42, 'port_range')

        snmpRowElements = self.snmpAgent.getSnmpData(serviceQueryBuilder)

        poolMemberToPoolQueryBuilder = SnmpQueryBuilder(CNTSVC_OID_OFFSET)
        poolMemberToPoolQueryBuilder.addQueryElement(2, 'cnt_name')
        poolMemberToPoolQueryBuilder.addQueryElement(3, 'svc_name')
        poolMemberToPoolElements = self.snmpAgent.getSnmpData(
            poolMemberToPoolQueryBuilder)

        svcToCntMap = {}
        for poolMemberToPoolElement in poolMemberToPoolElements:
            cnt = self.resourcePools[poolMemberToPoolElement.cnt_name]
            cntList = svcToCntMap.get(poolMemberToPoolElement.svc_name, [])
            cntList.append(cnt)
            svcToCntMap[poolMemberToPoolElement.svc_name] = cntList

        for snmpRowElement in snmpRowElements:
            poolMember = modeling.createHostOSH(snmpRowElement.ip, 'host_node')
            # KB specific: fix of port translations
            serviceAddressPort = snmpRowElement.port
            serviceAddress = modeling.createServiceAddressOsh(
                poolMember, snmpRowElement.ip, serviceAddressPort,
                CNT_PROTOCOL_MAP[snmpRowElement.protocol])

            self.OSHVResult.add(poolMember)

            if svcToCntMap.has_key(snmpRowElement.svc_name):
                cntList = svcToCntMap[snmpRowElement.svc_name]
                for cnt in cntList:
                    # KB specific: if there is not any port translation between the input and output IPs ports, create the same port
                    destinationPort = serviceAddressPort
                    destinationAddress = serviceAddress
                    if destinationPort == '0':
                        inputServiceAddress = self.resourcePoolsToServiceAddress[
                            cnt.getAttributeValue('data_name')]
                        destinationPort = inputServiceAddress.getAttributeValue(
                            'ipport_number')
                        destinationAddress = modeling.createServiceAddressOsh(
                            poolMember, snmpRowElement.ip, destinationPort,
                            CNT_PROTOCOL_MAP[snmpRowElement.protocol])
                        self.OSHVResult.add(destinationAddress)

                    self.OSHVResult.add(
                        modeling.createLinkOSH('member', cnt,
                                               destinationAddress))
            else:
                self.OSHVResult.add(serviceAddress)
                errobj = errorobject.createError(
                    errorcodes.NO_SERVICE_FOUND_FOR_NODE,
                    [snmpRowElement.svc_name],
                    'No service found for destination node')
                logger.reportWarningObject(errobj)
コード例 #26
0
 def discoverVirtualServices(self, virtualServerIndexToIpMap, alteon):
     queryBuilder = SnmpQueryBuilder(VIRTUAL_SERVICES)
     queryBuilder.addQueryElement(1, 'virtualServerIndex')
     queryBuilder.addQueryElement(2, 'index')
     queryBuilder.addQueryElement(3, 'virtualPort')
     queryBuilder.addQueryElement(4, 'realGroupIndex')
     queryBuilder.addQueryElement(5, 'realPort')
             
     virtualServices = self.snmpAgent.getSnmpData(queryBuilder)
     
     realGroupIndexToVirtualServer = {}
     for virtualService in virtualServices:
         ipAddress = virtualServerIndexToIpMap[virtualService.virtualServerIndex]
         virtualServerKey = virtualService.realGroupIndex.strip()
         
         virtualServerWrapper = VirtualServerWrapper(ipAddress, alteon, virtualService.virtualPort, virtualService.realPort)
         
         realGroupIndexToVirtualServer[virtualServerKey] = virtualServerWrapper
         
     self.discoverRealGroups(realGroupIndexToVirtualServer)            
コード例 #27
0
    def discoverF5(self, f5Osh):
        queryBuilder = SnmpQueryBuilder('1.4')
        queryBuilder.addQueryElement(1, 'name')
        queryBuilder.addQueryElement(2, 'version')
        queryBuilder.addQueryElement(3, 'build')
        queryBuilder.addQueryElement(4, 'edition')
        queryBuilder.addQueryElement(5, 'date')
        
        snmpAgent = SnmpAgent('1.3.6.1.4.1.3375.2', self.snmpAgent.snmpClient, self.Framework)
        
        try:
            productInformation = snmpAgent.getSnmpData(queryBuilder)[0]        
            f5Osh.setAttribute('application_version', productInformation.version)
        except:
            errorMsg = 'Failed to get general information'
            errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['snmp', 'general information'], errorMsg)
            logger.debugException(errorMsg)
            logger.reportWarningObject(errobj)

        self.discoverVirtualServers(f5Osh)
コード例 #28
0
    def discoverVirtualServers(self, f5Osh):
        queryBuilder = SnmpQueryBuilder('10.1.2.1')
        queryBuilder.addQueryElement(1, 'name')
        queryBuilder.addQueryElement(2, 'addressType')
        queryBuilder.addQueryElement(3, 'address', 'hexa')
        queryBuilder.addQueryElement(4, 'wildmaskType')
        queryBuilder.addQueryElement(5, 'wildmask')
        queryBuilder.addQueryElement(6, 'port')        
        queryBuilder.addQueryElement(9, 'enabled')        
        queryBuilder.addQueryElement(19, 'defaultPoolName')
        virtualServers = self.snmpAgent.getSnmpData(queryBuilder)

        nameToVirtualServerHelper = {}
        
        for virtualServer in virtualServers:
            if virtualServer.enabled == '0':
                continue
            
            #TODO: Deal with addressType. "0" means unknown, but we must specify port type when create ipServer osh
            ipAddress = self.convertToIp(virtualServer.address)
            if not ip_addr.isValidIpAddressNotZero(ipAddress):
                continue

            virtualServerHelper = VirtualServerHelper(virtualServer.name, ipAddress, f5Osh, virtualServer.port)
            virtualServerHelper.setDefaultPoolName(virtualServer.defaultPoolName)
            nameToVirtualServerHelper[virtualServer.name] = virtualServerHelper
            
        nameToPool = {}
        self.discoverPools(nameToVirtualServerHelper, f5Osh, nameToPool)
        self.discoverRules(nameToVirtualServerHelper, nameToPool)
        
        #report virtual servers only with links to cluster
        for virtualServerHelper in nameToVirtualServerHelper.values():
            if virtualServerHelper.hasAtLeastOneParentCluster():
                virtualServerHelper.addResultsToVector(self.OSHVResult)
            else:
                logger.debug("Virtual server %s was not reported since it is not linked to any cluster" % virtualServerHelper)
コード例 #29
0
    def discoverRealGroups(self, realGroupIndexToVirtualServer):
        queryBuilder = SnmpQueryBuilder(REAL_GROUPS)
        queryBuilder.addQueryElement(1, "index", "int")
        queryBuilder.addQueryElement(2, "realServers", "hexa")
        queryBuilder.addQueryElement(8, "groupName")

        realGroups = self.snmpAgent.getSnmpData(queryBuilder)
        serverList = self.discoverRealServers()
        self.discoverPortLinks()
        for realGroup in realGroups:
            cluster = ObjectStateHolder("loadbalancecluster")
            dataName = realGroup.groupName
            index = realGroup.index.strip()

            if not dataName:
                dataName = index
            cluster.setAttribute("data_name", dataName)
            self.OSHVResult.add(cluster)
            realPort = None
            if realGroupIndexToVirtualServer.has_key(index):
                virtualServerWrapper = realGroupIndexToVirtualServer[index]
                virtualServerWrapper.addResultsToVector(self.OSHVResult, cluster)
                realPort = realGroupIndexToVirtualServer[index].realPort
            else:
                logger.warn(
                    "Alteon real group index %s taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.3.3.1.1 does not match any virtual service's real group index taken from oid 1.3.6.1.4.1.1872.2.5.4.1.1.4.5.1"
                    % index
                )
                errobj = errorobject.createError(
                    errorcodes.FAILED_LINKING_ELEMENTS,
                    ["real group %s" % dataName, "virtual service"],
                    "Failed to link real group %s to virtual service" % dataName,
                )
                logger.reportWarningObject(errobj)

            realServerNumbers = parseMappingString(realGroup.realServers.strip())
            # reporting real ports from Virtual service table for each real server:
            for realServer in realServerNumbers:
                if serverList.has_key(realServer):
                    if realPort:
                        serviceAddress = modeling.createServiceAddressOsh(
                            serverList[realServer].getServer(),
                            serverList[realServer].getIPAddress(),
                            realPort,
                            modeling.SERVICEADDRESS_TYPE_TCP,
                        )
                        self.OSHVResult.add(serviceAddress)
                        self.OSHVResult.add(modeling.createLinkOSH("member", cluster, serviceAddress))
                    elif self.portMappings.has_key(realServer):
                        portMapping = self.getPortMapping(realServerindex)
                        for port in portMapping.getPorts():
                            serviceAddress = modeling.createServiceAddressOsh(
                                serverList[realServer].getServer(),
                                serverList[realServer].getIPAddress(),
                                port,
                                modeling.SERVICEADDRESS_TYPE_TCP,
                            )
                            self.OSHVResult.add(serviceAddress)
                            self.OSHVResult.add(modeling.createLinkOSH("member", cluster, serviceAddress))
                    else:
                        serviceAddress = modeling.createServiceAddressOsh(
                            serverList[realServer].getServer(),
                            serverList[realServer].getIPAddress(),
                            0,
                            modeling.SERVICEADDRESS_TYPE_TCP,
                            "unknown",
                        )
                        self.OSHVResult.add(serviceAddress)
                        self.OSHVResult.add(modeling.createLinkOSH("member", cluster, serviceAddress))
コード例 #30
0
    def discoverVirtualServices(self, virtualServerIndexToIpMap, alteon):
        queryBuilder = SnmpQueryBuilder(VIRTUAL_SERVICES)
        queryBuilder.addQueryElement(1, "virtualServerIndex")
        queryBuilder.addQueryElement(2, "index")
        queryBuilder.addQueryElement(3, "virtualPort")
        queryBuilder.addQueryElement(4, "realGroupIndex")
        queryBuilder.addQueryElement(5, "realPort")

        virtualServices = self.snmpAgent.getSnmpData(queryBuilder)

        realGroupIndexToVirtualServer = {}
        for virtualService in virtualServices:
            ipAddress = virtualServerIndexToIpMap[virtualService.virtualServerIndex]
            virtualServerKey = virtualService.realGroupIndex.strip()

            virtualServerWrapper = VirtualServerWrapper(
                ipAddress, alteon, virtualService.virtualPort, virtualService.realPort
            )

            realGroupIndexToVirtualServer[virtualServerKey] = virtualServerWrapper

        self.discoverRealGroups(realGroupIndexToVirtualServer)
コード例 #31
0
 def discoverPools(self, nameToVirtualServerHelper, f5Osh, nameToPool):
     queryBuilder = SnmpQueryBuilder('5.1.2.1')
     queryBuilder.addQueryElement(1, 'name')
     pools = self.snmpAgent.getSnmpData(queryBuilder)
     
     for pool in pools:
         poolOsh = ObjectStateHolder('loadbalancecluster')
         poolOsh.setAttribute('data_name', pool.name)
         self.add(poolOsh)            
         memberLink = modeling.createLinkOSH('membership', poolOsh, f5Osh)
         self.add(memberLink)
         nameToPool[pool.name] = poolOsh
         
         for name, virtualServerHelper in nameToVirtualServerHelper.items():
             if virtualServerHelper.getDefaultPoolName() == pool.name and not virtualServerHelper.hasParentCluster(pool.name):
                 virtualServerHelper.linkToContainingCluster(poolOsh, pool.name)
         
     queryBuilder = SnmpQueryBuilder('10.6.2.1')
     queryBuilder.addQueryElement(1, 'virtualServerName')
     queryBuilder.addQueryElement(2, 'poolName')
     queryBuilder.addQueryElement(3, 'poolDefaultRuleName')
     poolToServerEntries = self.snmpAgent.getSnmpData(queryBuilder)
     
     for poolToServerEntry in poolToServerEntries:
         try:
             virtualServerHelper = nameToVirtualServerHelper[poolToServerEntry.virtualServerName]
             poolOsh = nameToPool[poolToServerEntry.poolName]            
             if not virtualServerHelper.hasParentCluster(poolToServerEntry.poolName):
                 virtualServerHelper.linkToContainingCluster(poolOsh, poolToServerEntry.poolName)
         except:
             errorMsg = 'Failed to link %s server with %s pool' % (poolToServerEntry.virtualServerName, poolToServerEntry.poolName)
             errobj = errorobject.createError(errorcodes.FAILED_LINKING_ELEMENTS, ['%s server' % poolToServerEntry.virtualServerName, '%s pool' % poolToServerEntry.poolName], errorMsg)
             #TODO Change log level to debug
             logger.debugException(errorMsg)
             logger.reportWarningObject(errobj)
     
     self.discoverPoolMembers(nameToPool)
コード例 #32
0
 def discoverRules(self, nameToVirtualServerHelper, nameToPool):
     queryBuilder = SnmpQueryBuilder('10.8.2.1')
     queryBuilder.addQueryElement(1, 'serverName')
     queryBuilder.addQueryElement(2, 'ruleName')
     ruleToServerEntries = self.snmpAgent.getSnmpData(queryBuilder)
     ruleNameToServerName = {}        
     for ruleToServerEntry in ruleToServerEntries:
         ruleNameToServerName[ruleToServerEntry.ruleName] = ruleToServerEntry.serverName
     
     queryBuilder = SnmpQueryBuilder('8.1.2.1')
     queryBuilder.addQueryElement(1, 'name')
     queryBuilder.addQueryElement(2, 'definition')
     #Type is currently not used, consider about adding it to description
     queryBuilder.addQueryElement(3, 'type')
     
     rules = self.snmpAgent.getSnmpData(queryBuilder)
     for rule in rules:
         try:
             virtualServerHelper = nameToVirtualServerHelper[ruleNameToServerName[rule.name]]
             virtualServerOsh = virtualServerHelper.getOsh()
             ruleOsh = modeling.createConfigurationDocumentOSH(rule.name, '', rule.definition, virtualServerOsh)
             virtualServerHelper.addOsh(ruleOsh)
             lines = rule.definition.splitlines()
             lines = [line.strip() for line in lines if line and line.strip()]
             for line in lines:
                 if not line.startswith('#') and not re.search(';\s*\#', line):
                     poolRef = re.match("pool\s+(\S+)", line)
                     if poolRef:													   
                         poolName = poolRef.group(1)
                         logger.debug('Found pool ' + poolName + ' in rule ' + rule.name)
                         if nameToPool.has_key(poolName):
                             virtualServerHelper.linkToContainingCluster(nameToPool[poolName], poolName)
         except:
             errorMsg = 'Failed to obtain virtual server for rule %s' % rule.name
             errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['virtual server for rule %s' % rule.name], errorMsg)
             logger.debugException(errorMsg)
             logger.reportWarningObject(errobj)
コード例 #33
0
	def discoverServices(self):
		serviceQueryBuilder = SnmpQueryBuilder(SVC_OID_OFFSET)	
		serviceQueryBuilder.addQueryElement(1, 'svc_name')
		serviceQueryBuilder.addQueryElement(3, 'ip')
		serviceQueryBuilder.addQueryElement(4, 'protocol')
		serviceQueryBuilder.addQueryElement(5, 'port')
		serviceQueryBuilder.addQueryElement(41, 'ip_range')
		serviceQueryBuilder.addQueryElement(42, 'port_range')
		
		snmpRowElements = self.snmpAgent.getSnmpData(serviceQueryBuilder)
		
		poolMemberToPoolQueryBuilder = SnmpQueryBuilder(CNTSVC_OID_OFFSET)
		poolMemberToPoolQueryBuilder.addQueryElement(2, 'cnt_name')
		poolMemberToPoolQueryBuilder.addQueryElement(3, 'svc_name')
		poolMemberToPoolElements = self.snmpAgent.getSnmpData(poolMemberToPoolQueryBuilder)
		
		svcToCntMap = {}
		for poolMemberToPoolElement in poolMemberToPoolElements:
			cnt = self.resourcePools[poolMemberToPoolElement.cnt_name]
			cntList = svcToCntMap.get(poolMemberToPoolElement.svc_name, [])
			cntList.append(cnt)
			svcToCntMap[poolMemberToPoolElement.svc_name] = cntList
		
		for snmpRowElement in snmpRowElements:
			poolMember = modeling.createHostOSH(snmpRowElement.ip, 'host_node')
			# KB specific: fix of port translations
			serviceAddressPort = snmpRowElement.port
			serviceAddress = modeling.createServiceAddressOsh(poolMember,
											snmpRowElement.ip,
											serviceAddressPort,
											CNT_PROTOCOL_MAP[snmpRowElement.protocol])
			
			self.OSHVResult.add(poolMember)
			
			if svcToCntMap.has_key(snmpRowElement.svc_name):
				cntList = svcToCntMap[snmpRowElement.svc_name]
				for cnt in cntList:
					# KB specific: if there is not any port translation between the input and output IPs ports, create the same port
					destinationPort = serviceAddressPort
					destinationAddress = serviceAddress
					if destinationPort == '0':
						inputServiceAddress = self.resourcePoolsToServiceAddress[cnt.getAttributeValue('data_name')]
						destinationPort = inputServiceAddress.getAttributeValue('ipport_number')
						destinationAddress = modeling.createServiceAddressOsh(poolMember,
															snmpRowElement.ip,
															destinationPort,
															CNT_PROTOCOL_MAP[snmpRowElement.protocol])
						self.OSHVResult.add(destinationAddress)
						
					self.OSHVResult.add(modeling.createLinkOSH('member', cnt, destinationAddress))
			else:
				self.OSHVResult.add(serviceAddress)
				errobj = errorobject.createError(errorcodes.NO_SERVICE_FOUND_FOR_NODE, [snmpRowElement.svc_name], 'No service found for destination node')
				logger.reportWarningObject(errobj)
コード例 #34
0
    def discoverContentRules(self):
        contentRuleQueryBuilder = SnmpQueryBuilder(CNT_OID_OFFSET)
        contentRuleQueryBuilder.addQueryElement(2, 'cnt_name')
        contentRuleQueryBuilder.addQueryElement(4, 'ipserver_address')
        contentRuleQueryBuilder.addQueryElement(5, 'ipport_type')
        contentRuleQueryBuilder.addQueryElement(6, 'ipport_number')
        contentRuleQueryBuilder.addQueryElement(68, 'ip_range')
        snmpRowElements = self.snmpAgent.getSnmpData(contentRuleQueryBuilder)

        for snmpRowElement in snmpRowElements:
            virtualServer = modeling.createHostOSH(
                snmpRowElement.ipserver_address, 'clusteredservice')
            virtualServerHostKey = virtualServer.getAttributeValue('host_key')
            virtualServer.setAttribute('data_name', virtualServerHostKey)
            self.OSHVResult.add(
                modeling.createLinkOSH('owner', self.css, virtualServer))
            self.OSHVResult.add(virtualServer)

            resourcePool = ObjectStateHolder('loadbalancecluster')
            resourcePool.setStringAttribute('data_name',
                                            snmpRowElement.cnt_name)
            self.OSHVResult.add(
                modeling.createLinkOSH('contained', resourcePool,
                                       virtualServer))
            self.OSHVResult.add(resourcePool)
            self.resourcePools[snmpRowElement.cnt_name] = resourcePool

            serviceAddress = modeling.createServiceAddressOsh(
                virtualServer, snmpRowElement.ipserver_address,
                snmpRowElement.ipport_number,
                CNT_PROTOCOL_MAP[snmpRowElement.ipport_type])
            serviceAddress.setContainer(virtualServer)
            self.OSHVResult.add(serviceAddress)

            # KB specific: fix of port translations
            self.resourcePoolsToServiceAddress[
                snmpRowElement.cnt_name] = serviceAddress

            for i in range(int(snmpRowElement.ip_range)):
                #TODO: Add all IPs from range
                pass
コード例 #35
0
	def discoverContentRules(self):
		contentRuleQueryBuilder = SnmpQueryBuilder(CNT_OID_OFFSET)
		contentRuleQueryBuilder.addQueryElement(2, 'cnt_name')
		contentRuleQueryBuilder.addQueryElement(4, 'ipserver_address')
		contentRuleQueryBuilder.addQueryElement(5, 'ipport_type')
		contentRuleQueryBuilder.addQueryElement(6, 'ipport_number')
		contentRuleQueryBuilder.addQueryElement(68, 'ip_range')
		snmpRowElements = self.snmpAgent.getSnmpData(contentRuleQueryBuilder)
		
		for snmpRowElement in snmpRowElements:
			virtualServer = modeling.createHostOSH(snmpRowElement.ipserver_address, 'clusteredservice')
			virtualServerHostKey = virtualServer.getAttributeValue('host_key')
			virtualServer.setAttribute('data_name', virtualServerHostKey)
			self.OSHVResult.add(modeling.createLinkOSH('owner', self.css, virtualServer))
			self.OSHVResult.add(virtualServer)			
			
			resourcePool = ObjectStateHolder('loadbalancecluster')
			resourcePool.setStringAttribute('data_name', snmpRowElement.cnt_name)
			self.OSHVResult.add(modeling.createLinkOSH('contained', resourcePool, virtualServer))
			self.OSHVResult.add(resourcePool)
			self.resourcePools[snmpRowElement.cnt_name] = resourcePool
			
			serviceAddress = modeling.createServiceAddressOsh(virtualServer,
											snmpRowElement.ipserver_address,
											snmpRowElement.ipport_number,
											CNT_PROTOCOL_MAP[snmpRowElement.ipport_type])
			serviceAddress.setContainer(virtualServer)
			self.OSHVResult.add(serviceAddress)

			# KB specific: fix of port translations
			self.resourcePoolsToServiceAddress[snmpRowElement.cnt_name] = serviceAddress

			for i in range(int(snmpRowElement.ip_range)):
				#TODO: Add all IPs from range
				pass