def DiscoveryMain(Framework): Framework = jee_connection.EnhancedFramework(Framework) isAppResourcesDiscoveryEnabled = _asBoolean(Framework.getParameter('discoverAppResources')) isJmsResourcesDiscoveryEnabled = _asBoolean(Framework.getParameter('discoverJMSResources')) platform = jee.Platform.JBOSS try: r'''In addition to the credentials we have to specify port number and version of the platform. Credentials may be defined without such information that is very important for establishing connections ''' port = entity.WeakNumeric(int) port.set(Framework.getDestinationAttribute('port')) version = Framework.getDestinationAttribute('version') properties = Properties() properties.put(CollectorsConstants.PROTOCOL_ATTRIBUTE_PORT, str(port.value())) properties.put(AgentConstants.VERSION_PROPERTY, version) client = Framework.createClient(properties) jmxProvider = jmx.Provider(client) except (Exception, JException), exc: logger.warnException("Failed to establish connection") jee_connection.reportError(Framework, str(exc), platform.getName())
def _websphereJmxConnect(credentialId, ip, Framework): r'''@types: str, str, Framework -> Result @raise java.lang.Exception on connection failure @raise Exception on connection failure ''' properties = java.util.Properties() properties.setProperty(AgentConstants.VERSION_PROPERTY, '') properties.setProperty('credentialsId', credentialId) properties.setProperty('ip_address', ip) client = None try: client = Framework.createClient(properties) provider = jmx.Provider(client) discoverer = websphere_discoverer.ServerDiscovererByJmx(provider) discoverer.findServers() finally: client and client.close() return Result(True)
create client make discovery of domain and servers ''' platform = jee.Platform.WEBSPHERE 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()
def DiscoveryMain(Framework): # import must be placed here as they are conflicts with import list in checkcred.py import jee import jmx import jee_connection import jee_discoverer import weblogic import weblogic_discoverer import protocol ports = jee_connection.getDestinationPorts(Framework) ip, domain = jee_connection.getIpAndDomain(Framework) ip = jee.IpDescriptor(ip) resultVector = ObjectStateHolderVector() protocolName = ClientsConsts.WEBLOGIC_PROTOCOL_NAME # FIND AVAILABLE PROTOCOLS protocols = jee_connection.getAvailableProtocols(Framework, protocolName, ip.value()) if not protocols: msg = errormessages.makeErrorMessage( protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError( errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg) logger.reportErrorObject(errobj) else: # PREPARE CONNECTION MECHANISM platform = jee.Platform.WEBLOGIC spec = jee_connection.SpecificationByPorts(platform, ports) configManager = jee_connection.SucceededPortsConfigManager() factory = jee_connection.Factory(protocols, spec) connectionFailedMsgs = [] discoveryFailedMsgs = [] # ITERATOR OVER AVAILABLE CONNECTION CONFIGURATIONS AND MAKE ATTEMP TO ESTABLISH CONNECTION # TO THE PORT THAT HAVE NOT BEEN DISCOVERED PREVIOUSLY while factory.hasNextConnectionConfig(): try: config = factory.next() if configManager.isSimilarConfigSucceeded(config): continue client = factory.createClient(Framework, config) except (Exception, JException), exc: logger.warnException( "Failed to establish connection using %s" % config) connectionFailedMsgs.append(str(exc)) else: try: try: # CONNECTION ESTABLISHED - DISCOVER dnsResolver = jee_discoverer.DnsResolverDecorator( netutils.JavaDnsResolver(), client.getIpAddress()) credentialsfulServerRole = weblogic.HasCredentialInfoRole( client.getUserName(), client.getCredentialId(), protocolType=protocol.getAttribute( config.protocolObj, AgentConstants.PROP_WEBLOGIC_PROTOCOL), trustFileName=config.getProperty( AgentConstants.PROP_WEBLOGIC_TRUST_FILE_NAME), keyPemPath=config.getProperty( AgentConstants.PROP_WEBLOGIC_KEY_PEM_PATH), certPemPath=config.getProperty( AgentConstants.PROP_WEBLOGIC_CERT_PEM_PATH)) # set port used for this connection credentialsfulServerRole.connectionPort.set( client.getPort()) # prepare builders and reporters reporter = jee.ServerTopologyReporter( weblogic.ServerTopologyBuilder()) # maker domain topology discovery discoverer = weblogic_discoverer.ServerDiscovererByJmx( jmx.Provider(client)) domain = discoverer.discoverRunningServersInDomain() resultVector.addAll( jee_discoverer.discoverDomainTopology( config.portNumber.value(), client.getIpAddress(), domain, dnsResolver, credentialsfulServerRole, weblogic.ServerRole, reporter)) configManager.processAsSuccessful(config) except (Exception, JException), exc: logger.warnException("Failed to make a discovery") discoveryFailedMsgs.append(str(exc)) finally: if client is not None: client.close() else:
def DiscoveryMain(Framework): # import must be placed here as they are conflicts with import list in checkcred.py import jee import jmx import entity import jee_connection import jee_discoverer import websphere import websphere_discoverer ports = jee_connection.getDestinationPorts(Framework) ip = jee.IpDescriptor(Framework.getDestinationAttribute('ip_address')) platform = jee.Platform.WEBSPHERE # ESTABLISH CONNECTION # find all available protocols for the WebSphere protocolName = ClientsConsts.WEBSPHERE_PROTOCOL_NAME protocols = jee_connection.getAvailableProtocols(Framework, protocolName, ip.value()) resultVector = ObjectStateHolderVector() if not protocols: msg = errormessages.makeErrorMessage( protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError( errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg) logger.reportErrorObject(errobj) else: # iterate over configurations defined for each protocol and try to establish connection dnsResolver = jee_discoverer.DnsResolverDecorator( netutils.JavaDnsResolver(), ip.value()) spec = jee_connection.SpecificationByPorts(platform, ports) spec.addProperty( 'server_was_config', 'services:connectors:SOAP_CONNECTOR_ADDRESS:host,services:connectors:SOAP_CONNECTOR_ADDRESS:port,clusterName' ) spec.addProperty('datasource_was_config', 'jndiName,URL,propertySet,connectionPool') factory = jee_connection.Factory(protocols, spec) connectionFailedMsgs = [] discoveryFailedMsgs = [] while factory.hasNextConnectionConfig(): try: config = factory.next() client = factory.createClient(Framework, config) provider = jmx.Provider(client) hostOsh = modeling.createHostOSH(ip.value()) except JException, je: logger.warnException( "Failed to establish connection using %s" % config) connectionFailedMsgs.append(je.getMessage()) else: # connection established try: try: credentialsfulServerRole = websphere.HasCredentialInfoRole( client.getUserName(), credentialsId=client.getCredentialId(), keystoreFilePath=config.protocolObj. getProtocolAttribute( CollectorsConstants. WEBSPHERE_PROTOCOL_ATTRIBUTE_KEYSTORE), trustStoreFilePath=config.protocolObj. getProtocolAttribute( CollectorsConstants. WEBSPHERE_PROTOCOL_ATTRIBUTE_TRUSTSTORE)) # create builder and reporter for server topology reporter = jee.ServerTopologyReporter( websphere.ServerTopologyBuilder()) # make discovery itself discoverer = websphere_discoverer.ServerDiscovererByJmx( jmx.Provider(client)) domain = discoverer.discoverServersInDomain() resultVector.addAll( jee_discoverer.discoverDomainTopology( config.portNumber.value(), client.getIpAddress(), domain, dnsResolver, credentialsfulServerRole, websphere.ServerRole, reporter, setDomainIp=0)) #trying to find config file serverindex to report ports for node in domain.getNodes(): for server in node.getServers(): logger.debug( "trying to find config file serverindex for server: ", server) filePath = 'cells\\' + domain.getName( ) + '\\nodes\\' + server.nodeName + "\\" + 'serverindex.xml' logger.debug('file path:', filePath) try: fileContent = websphere_discoverer.getFileContent( provider, filePath) logger.debug('fileContent: ', fileContent) matches = re.findall( 'port\s*=\s*\"(\d+)\"', fileContent) if matches: for match in matches: print("Found port:%s" % match) resultVector.addAll( reportServiceEndpoints( ip.value(), match, hostOsh, server)) except: logger.debug('Document not found: ', filePath) # sentObjectsCount += vector.size() # _sendVectorImmediately(Framework, vector) except (Exception, JException), exc: logger.warnException("Failed to discover") discoveryFailedMsgs.append(str(exc)) finally: if client is not None: client.close() else: