def _getAdapterBindings(self, adapterNode): result = [] xpath = self.getXPath() bindings = xpath.evaluate(r'bindings/binding', adapterNode, XPathConstants.NODESET) if bindings: for bindingNum in xrange(bindings.getLength()): bindingNode = bindings.item(bindingNum) bindingName = xpath.evaluate(r'@name', bindingNode, XPathConstants.STRING) bindingMachine = xpath.evaluate(r'machine', bindingNode, XPathConstants.STRING) # Resolve machine IP try: ip = netutils.getLowestIp( self._dnsResolver.resolveIpsByHostname(bindingMachine)) except: logger.warn("Failed to resolve: ", bindingMachine) else: bindingMachine = ip bindingProductType = xpath.evaluate( r'product/type', bindingNode, XPathConstants.STRING) bindingProductVersion = xpath.evaluate( r'product/version', bindingNode, XPathConstants.STRING) bindingProductLocation = xpath.evaluate( r'product/location', bindingNode, XPathConstants.STRING) binding = tibco.AdapterBinding( bindingName, bindingMachine, tibco.Product(bindingProductType, bindingProductVersion, bindingProductLocation)) result.append(binding) return result
def _getAdapterBindings(self, adapterNode): result = [] xpath = self.getXPath() bindings = xpath.evaluate(r'bindings/binding', adapterNode, XPathConstants.NODESET) if bindings: for bindingNum in xrange(bindings.getLength()): bindingNode = bindings.item(bindingNum) bindingName = xpath.evaluate(r'@name', bindingNode, XPathConstants.STRING) bindingMachine = xpath.evaluate(r'machine', bindingNode, XPathConstants.STRING) # Resolve machine IP try: ip = netutils.getLowestIp(self._dnsResolver.resolveIpsByHostname(bindingMachine)) except: logger.warn("Failed to resolve: ", bindingMachine) else: bindingMachine = ip bindingProductType = xpath.evaluate(r'product/type', bindingNode, XPathConstants.STRING) bindingProductVersion = xpath.evaluate(r'product/version', bindingNode, XPathConstants.STRING) bindingProductLocation = xpath.evaluate(r'product/location', bindingNode, XPathConstants.STRING) binding = tibco.AdapterBinding(bindingName, bindingMachine, tibco.Product(bindingProductType, bindingProductVersion, bindingProductLocation)) result.append(binding) return result
def DiscoveryMain(Framework): OshvResult = ObjectStateHolderVector() hostOsh = None ## Destination data hostId = Framework.getDestinationAttribute('hostId') or None processRootId = Framework.getDestinationAttribute('processRootId') or None processPath = Framework.getDestinationAttribute('processPath') or None processCmdLine = Framework.getDestinationAttribute('processCmdLine') or None protocol = Framework.getDestinationAttribute('Protocol') ipAddress = Framework.getDestinationAttribute('ip_address') raw_paths = Framework.getParameter('emsadmin_tool_absolute_paths') or '' default_paths = [x.strip() for x in raw_paths.split(',')] ## Pattern parameters isJmsQueueDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_queues')) isJmsTopicDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discover_topics')) ## Container HOST OSH if hostId: hostOsh = modeling.createOshByCmdbIdString('host', hostId.strip()) OshvResult.add(hostOsh) logger.debug('[' + __name__ + ':DiscoveryMain] Got HOSTID <%s>' % hostId) ## EMS OSH if processRootId: processOsh = modeling.createOshByCmdbIdString('process', processRootId.strip()) OshvResult.add(processOsh) logger.debug('[' + __name__ + ':DiscoveryMain] Got Process ID <%s>' % processRootId) else: errMsg = "Invalid Tibco EMS Server CI ID received from server. This EMS server will not be processed" logger.error(errMsg) logger.reportError(errMsg) return OshvResult emsTopology = [] # Attempt to create a shell client try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) fallbackDnsResolver = tibco_discoverer.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(shell)]) dnsResolver = tibco_discoverer.CachedResolver(fallbackDnsResolver) fs = file_system.createFileSystem(shell) emsShellDiscoverer = tibco_discoverer.EmsDiscovererByShell(shell, fs) pathUtils = file_system.getPath(fs) emsPath = "%s/" % pathUtils.dirName(processPath) default_paths.insert(0, emsPath) # find out whether emsadmin tool exists and config path present in command line for ems_path in default_paths: configPath = emsShellDiscoverer.discoverConfigPath(ems_path, processCmdLine) if configPath: emsPath = ems_path logger.debug('Found ems admin utility path %s' % emsPath) logger.debug('Found ems config file path %s' % configPath) break if not emsPath: raise ValueError('Failed to discover ems admin utility path. No discovery possible.') listenUrls = emsShellDiscoverer.getListenUrls(configPath) credList = Framework.getAvailableProtocols(ipAddress, tibco.TIBCO_PROTOCOL) # Check if exists any credentials for TIBCO if credList: for cred in credList: for listenUrl in listenUrls: try: emsAdminCommand = tibco_discoverer.EmsAdminCommand(client, cred, emsPath, listenUrl) if testConnection(emsAdminCommand): emsDiscoverer = tibco_discoverer.EmsDiscovererByAdminCommand(emsAdminCommand) emsServer = emsDiscoverer.getEmsServerInfo() jmsServer = emsDiscoverer.extractJmsServerInfoFromUrl(listenUrl) if jmsServer: hostname = jmsServer.hostname try: ip = dnsResolver.resolveIpsByHostname(hostname) jmsServer.hostname = netutils.getLowestIp(ip) except: logger.debug("Cannot resolve %s host" % hostname) if emsServer: emsQueues = isJmsQueueDiscoveryEnabled and emsDiscoverer.getQueues() emsTopics = isJmsTopicDiscoveryEnabled and emsDiscoverer.getTopics() destinations = [] if emsQueues or emsTopics: emsQueues and destinations.extend(emsQueues) emsTopics and destinations.extend(emsTopics) emsDataItem = tibco_discoverer.EmsTopology(emsServer, jmsServer, destinations) emsTopology.append(emsDataItem) except tibco_discoverer.TibcoDiscovererException, ex: reportError(str(ex), tibco.TIBCO_PROTOCOL, Framework) except Exception, ex: reportError(str(ex), protocol, Framework) except JException, ex: msg = ex.getMessage() logger.debugException(msg) errormessages.resolveAndReport(msg, protocol, Framework)
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
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