def DiscoveryMain(Framework): # import must be placed here as they are conflicts with import list in checkcred.py import jee import jee_connection import jmx import jee_discoverer import jboss import jboss_discoverer Framework = jee_connection.EnhancedFramework(Framework) resultVector = ObjectStateHolderVector() protocolName = ClientsConsts.JBOSS_PROTOCOL_NAME platform = jee.Platform.JBOSS try: ports = jee_connection.getDestinationPorts(Framework) ip, domain = jee_connection.getIpAndDomain(Framework) ip = jee.IpDescriptor(ip) protocols = jee_connection.getAvailableProtocols(Framework, protocolName, ip.value()) except (Exception, JException), exc: logger.warnException(str(exc)) jee_connection.reportError(Framework, str(exc), platform.getName())
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:
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: