def getUsers(self, domainName): ''' Get users for specified domain name. Information about users contains name, description, UID, full name, lock status, disabled or enabled status. str -> list(User) @command: SELECT Description, Disabled, Domain, FullName, Lockout, Name, SID FROM Win32_UserAccount WHERE Domain = '<domainName>' @raise Exception: if WMI query failed ''' users = [] builder = self._provider.getBuilder( 'Win32_UserAccount').addWmiObjectProperties( 'Name', 'FullName', 'Description', 'SID', 'Disabled', 'Domain', 'Lockout') builder.addWhereClause("Domain = '%s'" % domainName) accounts = self._provider.getAgent().getWmiData(builder, timeout=180000) for account in accounts: user = User(account.Name, description=account.Description, uid=account.SID) user.fullName = account.FullName user.isDisabled = Boolean.valueOf(account.Disabled) user.domain = account.Domain user.isLocked = Boolean.valueOf(account.Lockout) users.append(user) return users
def DiscoveryMain(Framework): Framework = jee_connection.EnhancedFramework(Framework) port = entity.WeakNumeric(int) port.set(Framework.getDestinationAttribute('port')) version = Framework.getDestinationAttribute('version') resultVector = ObjectStateHolderVector() isAppResourcesDiscoveryEnabled = Boolean.valueOf( Framework.getParameter('discoverAppResources')) isJMSResourcesDiscoveryEnabled = Boolean.valueOf( Framework.getParameter('discoverJMSResources')) discoverDeployedOnlyApplications = Boolean.valueOf( Framework.getParameter("discoverDeployedOnlyApplications")) protocolType = (Framework.getDestinationAttribute('protocol') or ClientsConsts.HTTP_PROTOCOL_NAME) properties = Properties() properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, str(port.value())) properties.put(AgentConstants.VERSION_PROPERTY, version) properties.put(AgentConstants.PROP_WEBLOGIC_PROTOCOL, protocolType) platform = jee.Platform.WEBLOGIC try: client = Framework.createClient(properties) except (Exception, JException), exc: logger.warnException("Failed to establish connection") jee_connection.reportError(Framework, str(exc), platform.getName())
def DiscoveryMain(Framework): Framework = jee_connection.EnhancedFramework(Framework) port = entity.WeakNumeric(int) port.set(Framework.getDestinationAttribute('port')) version = Framework.getDestinationAttribute('version') resultVector = ObjectStateHolderVector() isAppResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverAppResources')) isJMSResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverJMSResources')) discoverDeployedOnlyApplications = Boolean.valueOf(Framework.getParameter("discoverDeployedOnlyApplications")) protocolType = (Framework.getDestinationAttribute('protocol') or ClientsConsts.HTTP_PROTOCOL_NAME) properties = Properties() properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, str(port.value())) properties.put(AgentConstants.VERSION_PROPERTY, version) properties.put(AgentConstants.PROP_WEBLOGIC_PROTOCOL, protocolType) platform = jee.Platform.WEBLOGIC try: client = Framework.createClient(properties) except (Exception, JException), exc: logger.warnException("Failed to establish connection") jee_connection.reportError(Framework, str(exc), platform.getName())
def _obtainParams(framework): zoneNameList = framework.getParameter("zoneList") splitRegexp = re.compile('[,;]') isNonEmptyString = lambda s: s and s.strip() zoneNameList = filter(isNonEmptyString, map(string.strip, splitRegexp.split(zoneNameList))) from java.lang import Boolean includeOutscopeIPs = framework.getParameter('includeOutscopeIPs') includeOutscopeIPs = Boolean.valueOf(includeOutscopeIPs) reportBrokenAliases = framework.getParameter('reportBrokenAliases') reportBrokenAliases = Boolean.valueOf(reportBrokenAliases) return zoneNameList, includeOutscopeIPs, reportBrokenAliases
def _obtainParams(framework): zoneNameList = framework.getParameter("zoneList") splitRegexp = re.compile("[,;]") isNonEmptyString = lambda s: s and s.strip() zoneNameList = filter(isNonEmptyString, map(string.strip, splitRegexp.split(zoneNameList))) from java.lang import Boolean includeOutscopeIPs = framework.getParameter("includeOutscopeIPs") includeOutscopeIPs = Boolean.valueOf(includeOutscopeIPs) reportBrokenAliases = framework.getParameter("reportBrokenAliases") reportBrokenAliases = Boolean.valueOf(reportBrokenAliases) return zoneNameList, includeOutscopeIPs, reportBrokenAliases
def discover(self, document, appName): adapters = [] # discoverer if document: logger.debug('Trying to find adapters for %s' % appName) xpath = self.getXPath() adapterNodeList = xpath.evaluate(r'/application/services/adapter', document, XPathConstants.NODESET) logger.debug('Found %s adapters' % adapterNodeList.getLength()) if adapterNodeList: for adapterNum in xrange(adapterNodeList.getLength()): adapterNode = adapterNodeList.item(adapterNum) # For reconciliation we will use adapter name as application name, # since from app signature we cannot get adapter name only application name and # binding name #adapterName = xpath.evaluate(r'@name', adapterNode, XPathConstants.STRING) adapterName = appName isEnabledStr = xpath.evaluate(r'enabled', adapterNode, XPathConstants.STRING) adapter = tibco.Adapter(adapterName, Boolean.valueOf(isEnabledStr)) tibco.each(adapter.addBinding, self._getAdapterBindings(adapterNode)) adapters.append(adapter) return adapters
def _massage_security_credential(self, result): _method_name = 'massage_security_credential' # Determine if the SecurityConfiguration/CredentialEncrypted can be removed if model_constants.SECURITY_CONFIGURATION_PASSWORD in result: # default is false if model_constants.SECURITY_CONFIGURATION_CD_ENABLED in result and \ Boolean.valueOf(result[model_constants.SECURITY_CONFIGURATION_CD_ENABLED]) == Boolean.TRUE: _logger.finer('WLSDPLY-06615', class_name=_class_name, method_name=_method_name) else: del result[model_constants.SECURITY_CONFIGURATION_PASSWORD] _logger.fine('WLSDPLY-06616', class_name=_class_name, method_name=_method_name) # Determine if the SecurityConfiguration/NodeManagerEncryptedPassword can be removed if model_constants.SECURITY_CONFIGURATION_NM_PASSWORD in result: if model_constants.MACHINE in self._dictionary or model_constants.UNIX_MACHINE in self._dictionary: _logger.finer('WLSDPLY-06645', class_name=_class_name, method_name=_method_name) else: del result[model_constants.SECURITY_CONFIGURATION_NM_PASSWORD] _logger.finer('WLSDPLY-06646', class_name=_class_name, method_name=_method_name)
def _obtainParams(framework): zoneNameList = framework.getParameter("zoneList") splitRegexp = re.compile('[,;]') isNonEmptyString = lambda s: s and s.strip() zoneNameList = filter(isNonEmptyString, map(string.strip, splitRegexp.split(zoneNameList))) from java.lang import Boolean includeOutscopeIPs = framework.getParameter('includeOutscopeIPs') includeOutscopeIPs = Boolean.valueOf(includeOutscopeIPs) reportBrokenAliases = framework.getParameter('reportBrokenAliases') reportBrokenAliases = Boolean.valueOf(reportBrokenAliases) ip = framework.getDestinationAttribute('ip_address') return zoneNameList, includeOutscopeIPs, ip, reportBrokenAliases
def _get_enqueue_replicated_flag(shell, pf_path): r'@types: shellutils.Shell, str -> bool?' output = _grep(shell, 'enque/server/replication', pf_path) if output: ENQUE_REPLICATION_RE = "enque/server/replication\s*=\s*(true|false)" m_obj = re.search(ENQUE_REPLICATION_RE, output.lower()) if m_obj: is_replicated = Boolean.valueOf(m_obj.group(1)) return is_replicated
def getUsers(self, domainName): ''' Get users for specified domain name. Information about users contains name, description, UID, full name, lock status, disabled or enabled status. str -> list(User) @command: SELECT Description, Disabled, Domain, FullName, Lockout, Name, SID FROM Win32_UserAccount WHERE Domain = '<domainName>' @raise Exception: if WMI query failed ''' users = [] builder = self._provider.getBuilder('Win32_UserAccount').addWmiObjectProperties('Name','FullName','Description','SID','Disabled','Domain','Lockout') builder.addWhereClause("Domain = '%s'" % domainName) accounts = self._provider.getAgent().getWmiData(builder, timeout = 180000) for account in accounts: user = User(account.Name, description = account.Description, uid = account.SID) user.fullName = account.FullName user.isDisabled = Boolean.valueOf(account.Disabled) user.domain = account.Domain user.isLocked = Boolean.valueOf(account.Lockout) users.append(user) return users
def onInit(): sponge.setVariable( "demo.readOnly", Boolean.valueOf(sponge.getProperty("demo.readOnly", "false"))) if sponge.getVariable("demo.readOnly"): sponge.logger.info("RUNNING IN THE READ ONLY MODE") sponge.addCategories( CategoryMeta("start").withLabel("Start"), CategoryMeta("basic").withLabel("Basic"), CategoryMeta("forms").withLabel("Forms"), CategoryMeta("types").withLabel("Types"), CategoryMeta("digits").withLabel("Digits"), CategoryMeta("admin").withLabel("Admin"), CategoryMeta("plus").withLabel("Extra"), CategoryMeta("events").withLabel("Events"))
def buildAdapter(self, adapter, binding): r'@types: Adapter, AdapterBinding -> ObjectStateHolder' assertFunc(adapter, ValueError('adapter is none')) assertFunc(binding, ValueError('binding is none')) adapterName = "%s\%s" % (adapter.getName(), binding.getName()) osh = ObjectStateHolder("tibco_adapter") osh.setAttribute('name', adapterName) osh.setAttribute('vendor', "tibco") osh.setAttribute('application_category', "Enterprise App") osh.setAttribute('discovered_product_name', 'Tibco Adapter') osh.setAttribute('application_path', binding.getProduct().getLocation()) osh.setAttribute('type', binding.getProduct().getType()) osh.setAttribute('binding_name', binding.getName()) osh.setBoolAttribute('enabled', Boolean.valueOf(adapter.isEnabled())) osh.setAttribute('version', binding.getProduct().getVersion()) osh.setAttribute("application_ip", binding.getMachineName()) return osh
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('protocol') protocolName = errormessages.protocolNames.get(protocol) or protocol matchDomainsToHostnamesValue = Framework.getParameter( ldom_discover.MATCH_DOMAIN_NAMES_TO_HOSTNAMES) matchDomainsToHostnames = Boolean.valueOf(matchDomainsToHostnamesValue) hostId = Framework.getDestinationAttribute('hostId') try: client = None try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) ldmCli = None ldm = None for ldmPath in ldom_discover.LDM_PATHS: ldmCli = ldom_discover.LdmCli(ldmPath) try: ldm = ldom_discover.getLdmInfo(shell, ldmCli) logger.debug("Found %s" % ldm) except ValueError, ex: logger.warn(str(ex)) else: break if ldm is None: raise ldom_discover.NoLdmFoundException() ldomTopology = ldom_discover.discoverLdomTopology(shell, ldmCli) reporter = ldom_report.createReporter(hostId, ldm, matchDomainsToHostnames) vector = reporter.report(ldomTopology) OSHVResult.addAll(vector) finally: client and client.close()
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('protocol') protocolName = errormessages.protocolNames.get(protocol) or protocol matchDomainsToHostnamesValue = Framework.getParameter(ldom_discover.MATCH_DOMAIN_NAMES_TO_HOSTNAMES) matchDomainsToHostnames = Boolean.valueOf(matchDomainsToHostnamesValue) hostId = Framework.getDestinationAttribute('hostId') try: client = None try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) ldmCli = None ldm = None for ldmPath in ldom_discover.LDM_PATHS: ldmCli = ldom_discover.LdmCli(ldmPath) try: ldm = ldom_discover.getLdmInfo(shell, ldmCli) logger.debug("Found %s" % ldm) except ValueError, ex: logger.warn(str(ex)) else: break if ldm is None: raise ldom_discover.NoLdmFoundException() ldomTopology = ldom_discover.discoverLdomTopology(shell, ldmCli) reporter = ldom_report.createReporter(hostId, ldm, matchDomainsToHostnames) vector = reporter.report(ldomTopology) OSHVResult.addAll(vector) finally: client and client.close()
def onInit(): sponge.setVariable("demo.readOnly", Boolean.valueOf(sponge.getProperty("demo.readOnly", "false"))) if sponge.getVariable("demo.readOnly"): sponge.logger.info("RUNNING IN THE READ ONLY MODE") sponge.addCategories( CategoryMeta("start").withLabel("Start") .withPredicate(lambda processor: processor.kb.name in ("start")), CategoryMeta("basic").withLabel("Basic") .withPredicate(lambda processor: processor.kb.name in ("demo", "engine")), CategoryMeta("forms").withLabel("Forms") .withPredicate(lambda processor: processor.kb.name in ("demoForms", "demoFormsLibraryArgs", "demoFormsLibraryRecord")), CategoryMeta("types").withLabel("Types") .withPredicate(lambda processor: processor.kb.name in ("types")), CategoryMeta("digits").withLabel("Digits") .withPredicate(lambda processor: processor.kb.name in ("digits")), CategoryMeta("admin").withLabel("Admin") .withPredicate(lambda processor: processor.kb.name in ("admin")), CategoryMeta("plus").withLabel("Extra") .withPredicate(lambda processor: processor.kb.name in ("demoPlus", "digitsLearn")), CategoryMeta("events").withLabel("Events") .withPredicate(lambda processor: processor.kb.name in ("events", "eventsNotification", "eventsMemo", "eventsCounter")) )
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 withVisibility(self, isPublic): r'@types: str' self.__visibility = (Boolean.valueOf(isPublic) and Image.VisiblityType.PUBLIC or Image.VisiblityType.PRIVATE) return self
def __init__(self, client, shellutils, uname, Framework): TCPDisByUnixShell.__init__(self, client, shellutils, uname, Framework) self.useLSOF = self.Framework.getParameter('useLSOF') self.useLSOF = Boolean.valueOf(self.useLSOF)
def __init__(self, client, shellutils, uname, Framework): TCPDisByShell.__init__(self, client, shellutils, Framework) self.uname = uname self.netstatOnly = self.Framework.getParameter('useNetstatOnly') self.netstatOnly = Boolean.valueOf(self.netstatOnly)
properties.put( "server_was_config", "services:connectors:SOAP_CONNECTOR_ADDRESS:host,services:connectors:SOAP_CONNECTOR_ADDRESS:port,clusterName", ) properties.put("datasource_was_config", "jndiName,URL,propertySet,connectionPool") try: client = Framework.createClient(properties) except (Exception, JException), exc: logger.warnException("Failed to establish connection") jee_connection.reportError(Framework, str(exc), platform.getName()) else: try: try: provider = jmx.Provider(client) dnsResolver = jee_discoverer.DnsResolverDecorator(netutils.JavaDnsResolver(), client.getIpAddress()) jdbcResourceDiscoveryEnabled = Boolean.valueOf(Framework.getParameter("discoverJDBCResources")) jmsResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter("discoverJMSResources")) applicationModulesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter("discoverAppResources")) namesOfServers = jee_connection.getParameterAsList(Framework, "servers") isAmongServersToDiscover = lambda s, l=namesOfServers: not l or s.getName() in l namesOfApps = jee_connection.getParameterAsList(Framework, "applications") isAmongApplicationsToDiscover = lambda a, l=namesOfApps: not l or a.getName() in l # create reporters and builders for websphere topology globalSettings = GeneralSettingsConfigFile.getInstance() enabledJeeEnhancedTopology = globalSettings.getPropertyBooleanValue("enableJeeEnhancedTopology", 0) if enabledJeeEnhancedTopology: logger.info("Reporting of enhanced JEE topology enabled") serverTopologyReporter = jee.ServerEnhancedTopologyReporter(websphere.ServerTopologyBuilder())
def _parseBoolean(value): if not value: return None from java.lang import Boolean return Boolean.valueOf(value)
def _asBoolean(value): '@types: str -> bool' return value and Boolean.valueOf(value)
properties = Properties() properties.put('server_was_config', 'services:connectors:SOAP_CONNECTOR_ADDRESS:host,services:connectors:SOAP_CONNECTOR_ADDRESS:port,clusterName') properties.put('datasource_was_config', 'jndiName,URL,propertySet,connectionPool') try: client = Framework.createClient(properties) except (Exception, JException), exc: logger.warnException("Failed to establish connection") jee_connection.reportError(Framework, str(exc), platform.getName()) else: try: try: provider = jmx.Provider( client ) dnsResolver = jee_discoverer.DnsResolverDecorator( netutils.JavaDnsResolver(), client.getIpAddress() ) jdbcResourceDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverJDBCResources')) jmsResourcesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverJMSResources')) applicationModulesDiscoveryEnabled = Boolean.valueOf(Framework.getParameter('discoverAppResources')) namesOfServers = jee_connection.getParameterAsList(Framework, 'servers') isAmongServersToDiscover = lambda s, l = namesOfServers: not l or s.getName() in l namesOfApps = jee_connection.getParameterAsList(Framework, 'applications') isAmongApplicationsToDiscover = lambda a, l = namesOfApps: not l or a.getName() in l # create reporters and builders for websphere topology globalSettings = GeneralSettingsConfigFile.getInstance() enabledJeeEnhancedTopology = globalSettings.getPropertyBooleanValue('enableJeeEnhancedTopology', 0) if enabledJeeEnhancedTopology: logger.info("Reporting of enhanced JEE topology enabled") serverTopologyReporter = jee.ServerEnhancedTopologyReporter(websphere.ServerTopologyBuilder())
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 hashCode(_self): return 76137213 ^ Boolean.valueOf(_self.clearCalled).hashCode()
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)