Ejemplo n.º 1
0
 def getOracleServerIP(self):
     try:
         host_address_result = self._client.executeQuery("select UTL_INADDR.get_host_address from dual")
         while host_address_result.next():
             ip = host_address_result.getString(1)
             if netutils.isValidIp(ip) and not netutils.isLoopbackIp(ip):
                 return ip
     except:
         logger.debugException('')
Ejemplo n.º 2
0
 def getOracleServerIP(self):
     try:
         host_address_result = self._client.executeQuery(
             "select UTL_INADDR.get_host_address from dual")
         while host_address_result.next():
             ip = host_address_result.getString(1)
             if netutils.isValidIp(ip) and not netutils.isLoopbackIp(ip):
                 return ip
     except:
         logger.debugException('')
Ejemplo n.º 3
0
    def getListeningIpAddress(self):
        if self.__dbIpAddress:
            return self.__dbIpAddress
        try:
            if not self.isRacInstance():
                self.__dbIpAddress = self._client.getIpAddress()
                return self.__dbIpAddress

            direct_ip = self.getOracleServerIP()
            server_name = self.getOracleServerName(
            ) or self.getOracleServerNameByInstance()
            probe_side_ip = None
            try:
                raw_probe_side_ip = netutils.getHostAddress(server_name)
                if netutils.isValidIp(
                        raw_probe_side_ip
                ) and not netutils.isLoopbackIp(raw_probe_side_ip):
                    probe_side_ip = raw_probe_side_ip
            except:
                logger.debugException('')

            if direct_ip and not probe_side_ip:
                self.__dbIpAddress = direct_ip

            if not direct_ip and probe_side_ip:
                self.__dbIpAddress = probe_side_ip

            if direct_ip and probe_side_ip:
                self.__dbIpAddress = probe_side_ip

            if self.__dbIpAddress:
                return self.__dbIpAddress

            raise ValueError('Server ip appeared to be incorrect')
        except:
            logger.debugException('')
            logger.reportWarning(
                'Failed to queue oracle server ip. Will report ip used for connection.'
            )
            self.__dbIpAddress = self._client.getIpAddress()
            return self._client.getIpAddress()
Ejemplo n.º 4
0
    def getListeningIpAddress(self):
        if self.__dbIpAddress:
            return self.__dbIpAddress
        try:
            if not self.isRacInstance():
                self.__dbIpAddress = self._client.getIpAddress()
                return self.__dbIpAddress

            direct_ip = self.getOracleServerIP()
            server_name = self.getOracleServerName() or self.getOracleServerNameByInstance()
            probe_side_ip = None
            try:
                raw_probe_side_ip = netutils.getHostAddress(server_name)
                if netutils.isValidIp(raw_probe_side_ip) and not netutils.isLoopbackIp(raw_probe_side_ip):
                    probe_side_ip = raw_probe_side_ip
            except:
                logger.debugException('')


            if direct_ip and not probe_side_ip:
                self.__dbIpAddress = direct_ip

            if not direct_ip and probe_side_ip:
                self.__dbIpAddress = probe_side_ip

            if direct_ip and probe_side_ip:
                self.__dbIpAddress = probe_side_ip

            if self.__dbIpAddress:
                return self.__dbIpAddress

            raise ValueError('Server ip appeared to be incorrect')
        except:
            logger.debugException('')
            logger.reportWarning('Failed to queue oracle server ip. Will report ip used for connection.')
            self.__dbIpAddress = self._client.getIpAddress()
            return self._client.getIpAddress()
Ejemplo n.º 5
0
def reportTrexHostNode(hostNode, topology, isBiaProduct):
    r'@types: TrexTopologyConfig.HostNode, TrexTopologyConfig, bool -> ObjectStateHolderVector'
    trexBuilder = sap_trex.Builder()
    trexReporter = sap_trex.Reporter(trexBuilder)
    hostReporter = sap_trex.HostReporter(sap_trex.HostBuilder())
    endpointReporter = netutils.EndpointReporter(
        netutils.ServiceEndpointBuilder())
    linkReporter = sap.LinkReporter()
    softwareBuilder = sap.SoftwareBuilder()
    # x) create sap system
    system = hostNode.system
    vector = ObjectStateHolderVector()

    # process NameServer endpoints and ignore loopback endpoints
    isLoopbackEndpoint = lambda e: netutils.isLoopbackIp(e.getAddress())
    _, endpoints = fptools.partition(isLoopbackEndpoint,
                                     hostNode.nameServerEndpoints)
    # x) create host OSH
    hostOsh = hostReporter.reportHostByHostname(hostNode.name)
    vector.add(hostOsh)
    # x) report IPs
    ips = map(netutils.Endpoint.getAddress, endpoints)
    ipOshs = map(modeling.createIpOSH, ips)
    fptools.each(vector.add, ipOshs)
    #vector.addAll(ipOshs)
    # x) report containment between host nad ips
    reportContainment = fptools.partiallyApply(linkReporter.reportContainment,
                                               hostOsh, fptools._)
    fptools.each(vector.add, map(reportContainment, ipOshs))
    # x) report end-points
    reportEndpoint = fptools.partiallyApply(endpointReporter.reportEndpoint,
                                            fptools._, hostOsh)
    endpointOshs = map(reportEndpoint, endpoints)
    fptools.each(vector.add, endpointOshs)
    # x) report TREX instance itself
    instanceOsh = trexReporter.reportInstance(first(system.getInstances()),
                                              hostOsh)
    # x) mark as BIA or plain-TREX
    productName = (isBiaProduct and sap_trex.Product.BIA.instanceProductName
                   or sap_trex.Product.TREX.instanceProductName)
    softwareBuilder.updateDiscoveredProductName(instanceOsh, productName)
    # x) set name server role (master, slave or 1st master)
    nameServerPort = first(endpoints).getPort()
    nameServerEndpoint = netutils.createTcpEndpoint(hostNode.name,
                                                    nameServerPort)
    topologyGlobals = topology.getGlobals()
    isMaster = nameServerEndpoint in (fptools.safeFunc(
        topologyGlobals.getMasterEndpoints)() or ())
    isActiveMaster = nameServerEndpoint in (fptools.safeFunc(
        topologyGlobals.getActiveMasterEndpoints)() or ())
    trexBuilder.updateNameServerMode(
        instanceOsh,
        (isMaster and
         (isActiveMaster and sap_trex.NameServerMode.FIRST_MASTER
          or sap_trex.NameServerMode.MASTER) or sap_trex.NameServerMode.SLAVE))

    vector.add(instanceOsh)
    # x) DO NOT report 'membership' between system and instance
    # Explanation:
    # sometimes you can discover systems that don't have relationship to current host.
    # This can lead to incorrect merging of to systems (inside OSH vector)
    # systemOsh = trexReporter.reportSystem(system)
    # vector.add(systemOsh)
    # vector.add(linkReporter.reportMembership(systemOsh, instanceOsh))

    # x) report 'usage' between instance and endpoints of name-server
    reportUsage = fptools.partiallyApply(linkReporter.reportUsage, instanceOsh,
                                         fptools._)
    fptools.each(vector.add, map(reportUsage, endpointOshs))
    return vector
Ejemplo n.º 6
0
def reportTrexHostNode(hostNode, topology, isBiaProduct):
    r'@types: TrexTopologyConfig.HostNode, TrexTopologyConfig, bool -> ObjectStateHolderVector'
    trexBuilder = sap_trex.Builder()
    trexReporter = sap_trex.Reporter(trexBuilder)
    hostReporter = sap_trex.HostReporter(sap_trex.HostBuilder())
    endpointReporter = netutils.EndpointReporter(netutils.ServiceEndpointBuilder())
    linkReporter = sap.LinkReporter()
    softwareBuilder = sap.SoftwareBuilder()
    # x) create sap system
    system = hostNode.system
    vector = ObjectStateHolderVector()

    # process NameServer endpoints and ignore loopback endpoints
    isLoopbackEndpoint = lambda e: netutils.isLoopbackIp(e.getAddress())
    _, endpoints = fptools.partition(isLoopbackEndpoint,
                                  hostNode.nameServerEndpoints)
    # x) create host OSH
    hostOsh = hostReporter.reportHostByHostname(hostNode.name)
    vector.add(hostOsh)
    # x) report IPs
    ips = map(netutils.Endpoint.getAddress, endpoints)
    ipOshs = map(modeling.createIpOSH, ips)
    fptools.each(vector.add, ipOshs)
    #vector.addAll(ipOshs)
    # x) report containment between host nad ips
    reportContainment = fptools.partiallyApply(linkReporter.reportContainment, hostOsh, fptools._)
    fptools.each(vector.add, map(reportContainment, ipOshs))
    # x) report end-points
    reportEndpoint = fptools.partiallyApply(endpointReporter.reportEndpoint, fptools._, hostOsh)
    endpointOshs = map(reportEndpoint, endpoints)
    fptools.each(vector.add, endpointOshs)
    # x) report TREX instance itself
    instanceOsh = trexReporter.reportInstance(first(system.getInstances()), hostOsh)
    # x) mark as BIA or plain-TREX
    productName = (isBiaProduct
                   and sap_trex.Product.BIA.instanceProductName
                   or sap_trex.Product.TREX.instanceProductName)
    softwareBuilder.updateDiscoveredProductName(instanceOsh, productName)
    # x) set name server role (master, slave or 1st master)
    nameServerPort = first(endpoints).getPort()
    nameServerEndpoint = netutils.createTcpEndpoint(hostNode.name, nameServerPort)
    topologyGlobals = topology.getGlobals()
    isMaster = nameServerEndpoint in (
                    fptools.safeFunc(topologyGlobals.getMasterEndpoints)() or ()
    )
    isActiveMaster = nameServerEndpoint in (
                    fptools.safeFunc(topologyGlobals.getActiveMasterEndpoints)() or ()
    )
    trexBuilder.updateNameServerMode( instanceOsh,
                (isMaster
                 and (isActiveMaster
                      and sap_trex.NameServerMode.FIRST_MASTER
                      or  sap_trex.NameServerMode.MASTER)
                 or sap_trex.NameServerMode.SLAVE))

    vector.add(instanceOsh)
    # x) DO NOT report 'membership' between system and instance
    # Explanation:
    # sometimes you can discover systems that don't have relationship to current host.
    # This can lead to incorrect merging of to systems (inside OSH vector)
    # systemOsh = trexReporter.reportSystem(system)
    # vector.add(systemOsh)
    # vector.add(linkReporter.reportMembership(systemOsh, instanceOsh))

    # x) report 'usage' between instance and endpoints of name-server
    reportUsage = fptools.partiallyApply(linkReporter.reportUsage, instanceOsh, fptools._)
    fptools.each(vector.add, map(reportUsage, endpointOshs))
    return vector
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    client = None
    hostOsh = None
    shell = None

    ## Destination data
    hostId = Framework.getDestinationAttribute('hostId') or None
    bwId = Framework.getDestinationAttribute('bwId') or None
    bwPath = Framework.getDestinationAttribute('bwPath') or None
    protocol = Framework.getDestinationAttribute('Protocol')
    ip_address = Framework.getDestinationAttribute('ip_address')
    tmpDirPath = Framework.getParameter('temp_directory') or '/tmp'
    isDiscoverJms = Framework.getParameter('discover_jms_topology') or "true"
    isDiscoverJms = Boolean.valueOf(isDiscoverJms)

    ## Container HOST OSH
    if hostId:
        hostOsh = modeling.createOshByCmdbIdString('node', hostId.strip())
        OSHVResult.add(hostOsh)
        logger.debug('[' + __name__ + ':DiscoveryMain] Got HOSTID <%s>' % hostId)

    ## Pre-discovered Business Works CI
    bwOsh = None
    if bwId:
        bwOsh = modeling.createOshByCmdbIdString('tibco_business_works', bwId.strip())
        logger.debug('[' + __name__ + ':DiscoveryMain] Got bwId <%s>' % bwId)
    else:
        errMsg = '[' + __name__ + ':DiscoveryMain] Invalid TibcoBusinessWorks CI ID received from server. This BW will not be processed'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult


    if not tmpDirPath:
        errMsg = '[' + __name__ + ':DiscoveryMain] temp_directory parameter has not been set correctly. Discovery cannot continue until this parameter is set with a remote directory with write permissions.'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult

    try:
        try:
            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)
            credList = Framework.getAvailableProtocols(ip_address, tibco.TIBCO_PROTOCOL)
            logger.info("Found tibco credentials: %s" % len(credList))

            fs = tibco_discoverer.createFileSystem(shell)

            bw = tibco_discoverer.BusinessWorksDiscoverer().findBWVersionFromPath(bwPath)
            domains = tibco_discoverer.BusinessWorksDomainDiscoverer(shell, fs).discover(bwPath)
            traHomeDiscoverer = tibco_discoverer.TicboTraHomeDiscoverer(shell)
            traHomes = traHomeDiscoverer.discover()
            fallbackDnsResolver = tibco_discoverer.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(shell)])
            dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver)

            if traHomes and bw:
                traPath = traHomes[0]
                for domain in domains:
                    logger.info("Visit %s" % domain)
                    try:
                        applications = None
                        # Check if we have any credential for TIBCO
                        if credList:
                            for credId in credList:
                                adminCommand = tibco_discoverer.AppManageAdminCommand(client, credId, "./")
                                adapterDiscoverer = tibco_discoverer.TibcoAdapterDiscoverer(dnsResolver)
                                appDiscoverer = tibco_discoverer.BusinessWorksApplicationDiscoverer(shell, fs, adminCommand, adapterDiscoverer)
                                applications = appDiscoverer.discover(domain.getName(), traPath, tmpDirPath, discoverJmsTopology=isDiscoverJms)
                            if applications:
                                tibco.each(domain.addApplication, applications)
                        else:
                            msg = errormessages.makeErrorMessage(tibco.TIBCO_PROTOCOL, pattern=errormessages.ERROR_NO_CREDENTIALS)
                            errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [ tibco.TIBCO_PROTOCOL ], msg)
                            logger.reportErrorObject(errobj)

                        bw.addDomain(domain)
                    except tibco_discoverer.TibcoDiscovererException, exc:
                        logger.debugException(str(exc))
                        errorobj = errorobject.createError(errorcodes.FAILED_RUNNING_DISCOVERY_WITH_CLIENT_TYPE, [ 'tibco', 'error: %s' % str(exc)], str(exc))
                        logger.reportErrorObject(errorobj)
        except:
            logger.debugException('')
            exInfo = logger.prepareJythonStackTrace('[' + __name__ + ':DiscoveryMain] Error connecting: ')
            errormessages.resolveAndReport(exInfo, protocol, Framework)
        else:
            # Reporting
            logger.debug("--- Start reporting ---")
            reporter = tibco.TopologyReporter(tibco.TopologyBuilder())
            bwOsh = reporter.reportBusinessWorks(bw, hostOsh, bwId)
            OSHVResult.add(bwOsh)
            endpointReporter = netutils.EndpointReporter(netutils.ServiceEndpointBuilder())

            for domain in domains:
                domainOsh = reporter.reportBusinessWorksDomain(domain)
                OSHVResult.add(domainOsh)
                OSHVResult.add(reporter.reportBWAndDomainLink(domainOsh, bwOsh))
                for app in domain.getApplications():
                    appOsh = reporter.reportBusinessWorksApp(app, bwOsh)
                    OSHVResult.add(appOsh)
                    if app.getJmsServers():
                        for jmsServer in app.getJmsServers():

                            # Trying to resolver host name
                            try:
                                ip = netutils.getLowestIp(dnsResolver.resolveIpsByHostname(jmsServer.hostname))
                                if ip:
                                    jmsServer.hostname = ip
                            except Exception, ex:
                                logger.debugException(str(ex))

                            if netutils.isValidIp(jmsServer.hostname) and not netutils.isLoopbackIp(jmsServer.hostname):
                                jmsHostOsh = modeling.createHostOSH(jmsServer.hostname)
                                emsServerOsh = reporter.reportEMSServer(tibco.EmsServer(), jmsHostOsh)
                                jmsServerOsh = reporter.reportJmsServer(jmsServer, emsServerOsh)
                                endpoint = netutils.createTcpEndpoint(jmsServer.hostname, jmsServer.getPort())
                                serviceOsh = endpointReporter.reportEndpoint(endpoint, jmsHostOsh)
                                linkOsh = reporter.reportEmsServerServiceAddressLink(emsServerOsh, serviceOsh)
                                OSHVResult.add(emsServerOsh)
                                OSHVResult.add(jmsHostOsh)
                                OSHVResult.add(jmsServerOsh)
                                OSHVResult.add(serviceOsh)
                                OSHVResult.add(linkOsh)
                                for jmsQueue in app.getJmsQueues():
                                    OSHVResult.addAll(reporter.reportJmsDestinationTopology(jmsQueue, jmsServerOsh, appOsh))
                                for jmsTopic in app.getJmsTopics():
                                    OSHVResult.addAll(reporter.reportJmsDestinationTopology(jmsTopic, jmsServerOsh, appOsh))
                    if app.getAdapters():
                        for adapter in app.getAdapters():
                            OSHVResult.addAll(reporter.reportAdapterTopology(adapter, appOsh))

    finally:
        if shell:
            ## Close shell connection
            shell.closeClient()

    return OSHVResult
Ejemplo n.º 8
0
    def parseLSOFNotListen(self, line, listenIpPorts):
        try:
            IpPortIpPortStatusListenArray = None
            try:
                IpPortIpPortStatusListenArray = re.search(self.TCPRegExp, line)
            except:
                return TCPDiscovery.OK
            if IpPortIpPortStatusListenArray == None:
                return TCPDiscovery.OK

            linkStatus = IpPortIpPortStatusListenArray.group(3)

            if self.isUndefinedState(linkStatus) \
            or linkStatus.lower() in ('closed', 'closing', self.LISTEN_str.lower()):
                logger.debug('Skipping %s links status the line %s' % (linkStatus, line))
                return TCPDiscovery.OK

            if line.lower().find('udp') != -1:
                logger.debug('Found not listen udp entry, skipping the line %s' % line)
                return TCPDiscovery.OK

#            logger.debug('non-listener - line ->', line)

            pid = IpPortIpPortStatusListenArray.group(1)
            connectionStr = IpPortIpPortStatusListenArray.group(2)
            if not '->' in connectionStr:
                logger.debug('Found incomplete connection, skipping the line %s' % line)
                return TCPDiscovery.OK
            connection = connectionStr.replace('->',':').split(':')

            if len(connection) != 4:
                message = 'It appears like lsof on destination %s does not work properly(wrong version?).'
                logger.debug(message)
                return TCPDisByLSOFableShell.LSOF_WRONG_VERSION_ERROR
            #Currently ipV6 is not supported, but be aware in case of things change, that
            #lsof output for ipV6 has much more ':' symbols:
            #java 180446 root 111u IPv6 0xf10007000010b2a0 0t0 TCP [::1]:*->[::1]:32784

            iIP1     = connection[0]
            iPort1     = int(long(connection[1]) & 0xffff)
            iIP2     = connection[2]
            iPort2     = int(long(connection[3]) & 0xffff)

            if not self.isIpv4(iIP1) or not self.isIpv4(iIP2):
                logger.debug ('Skipping not valid IPv4 addresses %s->%s' % (iIP1, iIP2))
                return TCPDiscovery.OK

            if (iPort1 == 0) or (iPort2 == 0):
                return TCPDiscovery.OK

            if not netutils.isValidIp(iIP1):
                errorMessage = 'On parsing non listen ports by lsof for protocol tcp extracted invalid ip:<' + iIP1 + '>'
                logger.warn(errorMessage)
                errobj = errorobject.createError(errorcodes.IP_PARSING_ERROR, ['tcp', iIP1, 'On parsing non listen ports by lsof'], errorMessage)
                logger.reportWarningObject(errobj)
                return TCPDiscovery.OK

            if not netutils.isValidIp(iIP2):
                errorMessage = 'On parsing listen ports by netstat for protocol tcp extracted invalid ip:<' + iIP2 + '>'
                logger.warn('parseLSOFNotListen:failed to process TCP entry: ', line)
                errobj = errorobject.createError(errorcodes.IP_PARSING_ERROR, ['tcp', iIP1, 'On parsing non listen ports by lsof'], errorMessage)
                logger.reportWarningObject(errobj)
                return TCPDiscovery.OK

            if netutils.isLoopbackIp(iIP1) or netutils.isLoopbackIp(iIP2):
                return TCPDiscovery.OK

            ipPort = '%s:%d' % (iIP1, iPort1)
            if not ipPort in listenIpPorts:
                self._addTcpData(iIP1, iPort1, pid, 0, modeling.TCP_PROTOCOL)

            # if ip1 and ip2 are the same then the same data will appear twice
            # so we have to discard one of the rows
            # 10.10.10.10   80  10.10.10.10   50
            # 10.10.10.10   50  10.10.10.10   80
#            if (iIP1 == iIP2) and (iPort1 > iPort2):
#                temp = iPort1
#                iPort1 = iPort2
#                iPort2 = temp

            self.pdu.addTcpConnection(iIP1, iPort1, iIP2, iPort2)
#            self.pdu.addTcpConnection(iIP2, iPort2, iIP1, iPort1)
            return TCPDiscovery.OK

        except:
            logger.errorException('parseLSOFNotListen:Failed parsing line: ', line)
            return TCPDiscovery.ERROR
Ejemplo n.º 9
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    client = None
    hostOsh = None
    shell = None

    ## Destination data
    hostId = Framework.getDestinationAttribute('hostId') or None
    bwId = Framework.getDestinationAttribute('bwId') or None
    bwPath = Framework.getDestinationAttribute('bwPath') or None
    protocol = Framework.getDestinationAttribute('Protocol')
    ip_address = Framework.getDestinationAttribute('ip_address')
    tmpDirPath = Framework.getParameter('temp_directory') or '/tmp'
    isDiscoverJms = Framework.getParameter('discover_jms_topology') or "true"
    isDiscoverJms = Boolean.valueOf(isDiscoverJms)

    ## Container HOST OSH
    if hostId:
        hostOsh = modeling.createOshByCmdbIdString('node', hostId.strip())
        OSHVResult.add(hostOsh)
        logger.debug('[' + __name__ +
                     ':DiscoveryMain] Got HOSTID <%s>' % hostId)

    ## Pre-discovered Business Works CI
    bwOsh = None
    if bwId:
        bwOsh = modeling.createOshByCmdbIdString('tibco_business_works',
                                                 bwId.strip())
        logger.debug('[' + __name__ + ':DiscoveryMain] Got bwId <%s>' % bwId)
    else:
        errMsg = '[' + __name__ + ':DiscoveryMain] Invalid TibcoBusinessWorks CI ID received from server. This BW will not be processed'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult

    if not tmpDirPath:
        errMsg = '[' + __name__ + ':DiscoveryMain] temp_directory parameter has not been set correctly. Discovery cannot continue until this parameter is set with a remote directory with write permissions.'
        logger.error(errMsg)
        logger.reportError(errMsg)
        return OSHVResult

    try:
        try:
            client = Framework.createClient()
            shell = shellutils.ShellFactory().createShell(client)
            credList = Framework.getAvailableProtocols(ip_address,
                                                       tibco.TIBCO_PROTOCOL)
            logger.info("Found tibco credentials: %s" % len(credList))

            fs = tibco_discoverer.createFileSystem(shell)

            bw = tibco_discoverer.BusinessWorksDiscoverer(
            ).findBWVersionFromPath(bwPath)
            domains = tibco_discoverer.BusinessWorksDomainDiscoverer(
                shell, fs).discover(bwPath)
            traHomeDiscoverer = tibco_discoverer.TicboTraHomeDiscoverer(shell)
            traHomes = traHomeDiscoverer.discover()
            fallbackDnsResolver = tibco_discoverer.FallbackResolver([
                netutils.JavaDnsResolver(),
                netutils.DnsResolverByShell(shell)
            ])
            dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver)

            if traHomes and bw:
                traPath = traHomes[0]
                for domain in domains:
                    logger.info("Visit %s" % domain)
                    try:
                        applications = None
                        # Check if we have any credential for TIBCO
                        if credList:
                            for credId in credList:
                                adminCommand = tibco_discoverer.AppManageAdminCommand(
                                    client, credId, "./")
                                adapterDiscoverer = tibco_discoverer.TibcoAdapterDiscoverer(
                                    dnsResolver)
                                appDiscoverer = tibco_discoverer.BusinessWorksApplicationDiscoverer(
                                    shell, fs, adminCommand, adapterDiscoverer)
                                applications = appDiscoverer.discover(
                                    domain.getName(),
                                    traPath,
                                    tmpDirPath,
                                    discoverJmsTopology=isDiscoverJms)
                            if applications:
                                tibco.each(domain.addApplication, applications)
                        else:
                            msg = errormessages.makeErrorMessage(
                                tibco.TIBCO_PROTOCOL,
                                pattern=errormessages.ERROR_NO_CREDENTIALS)
                            errobj = errorobject.createError(
                                errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP,
                                [tibco.TIBCO_PROTOCOL], msg)
                            logger.reportErrorObject(errobj)

                        bw.addDomain(domain)
                    except tibco_discoverer.TibcoDiscovererException, exc:
                        logger.debugException(str(exc))
                        errorobj = errorobject.createError(
                            errorcodes.
                            FAILED_RUNNING_DISCOVERY_WITH_CLIENT_TYPE,
                            ['tibco', 'error: %s' % str(exc)], str(exc))
                        logger.reportErrorObject(errorobj)
        except:
            logger.debugException('')
            exInfo = logger.prepareJythonStackTrace(
                '[' + __name__ + ':DiscoveryMain] Error connecting: ')
            errormessages.resolveAndReport(exInfo, protocol, Framework)
        else:
            # Reporting
            logger.debug("--- Start reporting ---")
            reporter = tibco.TopologyReporter(tibco.TopologyBuilder())
            bwOsh = reporter.reportBusinessWorks(bw, hostOsh, bwId)
            OSHVResult.add(bwOsh)
            endpointReporter = netutils.EndpointReporter(
                netutils.ServiceEndpointBuilder())

            for domain in domains:
                domainOsh = reporter.reportBusinessWorksDomain(domain)
                OSHVResult.add(domainOsh)
                OSHVResult.add(reporter.reportBWAndDomainLink(
                    domainOsh, bwOsh))
                for app in domain.getApplications():
                    appOsh = reporter.reportBusinessWorksApp(app, bwOsh)
                    OSHVResult.add(appOsh)
                    if app.getJmsServers():
                        for jmsServer in app.getJmsServers():

                            # Trying to resolver host name
                            try:
                                ip = netutils.getLowestIp(
                                    dnsResolver.resolveIpsByHostname(
                                        jmsServer.hostname))
                                if ip:
                                    jmsServer.hostname = ip
                            except Exception, ex:
                                logger.debugException(str(ex))

                            if netutils.isValidIp(
                                    jmsServer.hostname
                            ) and not netutils.isLoopbackIp(
                                    jmsServer.hostname):
                                jmsHostOsh = modeling.createHostOSH(
                                    jmsServer.hostname)
                                emsServerOsh = reporter.reportEMSServer(
                                    tibco.EmsServer(), jmsHostOsh)
                                jmsServerOsh = reporter.reportJmsServer(
                                    jmsServer, emsServerOsh)
                                endpoint = netutils.createTcpEndpoint(
                                    jmsServer.hostname, jmsServer.getPort())
                                serviceOsh = endpointReporter.reportEndpoint(
                                    endpoint, jmsHostOsh)
                                linkOsh = reporter.reportEmsServerServiceAddressLink(
                                    emsServerOsh, serviceOsh)
                                OSHVResult.add(emsServerOsh)
                                OSHVResult.add(jmsHostOsh)
                                OSHVResult.add(jmsServerOsh)
                                OSHVResult.add(serviceOsh)
                                OSHVResult.add(linkOsh)
                                for jmsQueue in app.getJmsQueues():
                                    OSHVResult.addAll(
                                        reporter.reportJmsDestinationTopology(
                                            jmsQueue, jmsServerOsh, appOsh))
                                for jmsTopic in app.getJmsTopics():
                                    OSHVResult.addAll(
                                        reporter.reportJmsDestinationTopology(
                                            jmsTopic, jmsServerOsh, appOsh))
                    if app.getAdapters():
                        for adapter in app.getAdapters():
                            OSHVResult.addAll(
                                reporter.reportAdapterTopology(
                                    adapter, appOsh))

    finally:
        if shell:
            ## Close shell connection
            shell.closeClient()

    return OSHVResult