def DiscoveryMain(framework): vector = ObjectStateHolderVector() protocol = 'local_shell' try: zoneNameList, includeOutscopeIPs, ip, reportBrokenAliases = _obtainParams( framework) if not zoneNameList: logger.reportError('List of zones for transfer is not specified') return client = framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) shell = None try: shell = shellutils.ShellUtils(client) #pass name server IP to the discoverer dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell, ip) zoneTopologies = dns_discoverer.discoverDnsZoneTopologies( dnsDiscoverer, zoneNameList, protocol) vector.addAll( dns_discoverer.reportTopologies(zoneTopologies, includeOutscopeIPs, reportBrokenAliases)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, framework)
def DiscoveryMain(framework): vector = ObjectStateHolderVector() protocol = framework.getDestinationAttribute('Protocol') try: client = framework.createClient() shell = None try: shell = shellutils.ShellUtils(client) dnsDiscoverer = dns_discoverer.createDiscovererByShell(shell) params = _obtainParams(framework) zoneNameList, includeOutscopeIPs, reportBrokenAliases = params zoneTopologies = dns_discoverer.discoverDnsZoneTopologies( dnsDiscoverer, zoneNameList, protocol) vector.addAll( dns_discoverer.reportTopologies(zoneTopologies, includeOutscopeIPs, reportBrokenAliases)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute('Protocol') try: try: try: hostName = Framework.getDestinationAttribute('hostname') msMqManagerUcmdbId = Framework.getDestinationAttribute( 'msmq_id') msMqManagerOsh = modeling.createOshByCmdbIdString( 'msmqmanager', msMqManagerUcmdbId) client = Framework.createClient() shell = shellutils.ShellUtils(client) msMqDiscoverer = MsMqDiscoverer(shell, msMqManagerOsh, hostName) if msMqDiscoverer: msMqDiscoverer.discover() msMqDiscoverer.addResultsToVector(OSHVResult) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') if OSHVResult.size() == 0: raise Exception, "Failed getting information about Microsoft Message Queue" except JavaException, ex: msg = ex.getMessage() errormessages.resolveAndReport(msg, protocol, Framework) except: msg = logger.prepareJythonStackTrace('') errormessages.resolveAndReport(msg, protocol, Framework) return OSHVResult
def getShellUtils(Framework, shellName, credentials, ip, codepage, warningsList, errorsList): failedPorts = [] #check which credential is good for the shell: client = None for credentialId in credentials: try: port = None props = Properties() props.setProperty(BaseAgent.ENCODING, codepage) props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, credentialId) logger.debug('try credential %s' % credentialId) client = Framework.createClient(props) shellUtils = shellutils.ShellUtils(client, None, shellName) if shellUtils: return (shellUtils, credentialId) except IOException, ioEx: strException = str(ioEx.getMessage()) errormessages.resolveAndAddToObjectsCollections( strException, shellName, warningsList, errorsList) if client: client.close() # we failed to connect - add the problematic port to failedPorts list if port: failedPorts.append(port) except (UnsupportedEncodingException, UnsupportedCharsetException), ex: strException = str(ex.getClass().getName()) shouldStop = errormessages.resolveAndAddToObjectsCollections( strException, shellName, warningsList, errorsList) if client: client.close() if shouldStop: return (None, None)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None defOraHomes = Framework.getParameter('OracleHomes') hostPrimaryIP = Framework.getDestinationAttribute('ip_address') protocol = Framework.getDestinationAttribute('Protocol') listenerNames = Framework.getTriggerCIDataAsList('listener_names') listenerPaths = Framework.getTriggerCIDataAsList('listener_process_path') errorMessage = None try: client = Framework.createClient() try: shell = shellutils.ShellUtils(client) hostOSH = modeling.createHostOSH(hostPrimaryIP) OSHVResult.add(hostOSH) if len(listenerPaths) < len(listenerNames): path = listenerPaths[0] for i in range(len(listenerNames) - len(listenerPaths)): listenerPaths.append(path) for i in range(len(listenerPaths)): try: listenerPath = listenerPaths[i] listenerName = listenerNames[i] listenerConf = ListenerConfiguration(shell, listenerName, listenerPath, defOraHomes) listenerConf.discover() listenedIPs = listenerConf.getListenedIPsAsString() resolver = DNSResolver(shell, None, hostPrimaryIP) ipPrim = resolver.resolveIpByHostname() if ipPrim and ipPrim != hostPrimaryIP: hostPrimaryIP = ipPrim resolver = DNSResolver(shell, None, hostPrimaryIP) #for UCMDB 9.x due to new reconsiliation FQDN is not vital hostDnsName = resolver.getDnsName() or ' ' if hostDnsName and listenedIPs: listenedFull = hostDnsName + ':' + hostPrimaryIP + '@' + listenedIPs listenerName = listenerConf.getListenerName() listenerVersion = listenerConf.getVersion() listenerOSH = createListenerOSH(hostOSH, listenedFull, listenerName, listenerVersion) if listenerOSH: OSHVResult.add(listenerOSH) else: Framework.reportWarning('Failed to create listener OSH. Either host name or listened ips are not defined.') except: logger.debugException('') Framework.reportWarning('Failed to discover one or more listeners parameters.') finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: errorMessage = ex.getMessage()
def __init__(self, shellClient, Framework=None): self.shellClient = shellutils.ShellUtils(shellClient) self.languageName = self.shellClient.osLanguage.bundlePostfix self.langBund = Framework.getEnvironmentInformation().getBundle('msExchange', self.languageName) self.ERROR_COMMAND_NOT_RECOGNIZED = self.langBund.getString('not_recognized_command') self.ERROR_64_BIT_MACHINE = self.langBund.getString('no_windows_powershell') self.ERROR_SYSTEM_CANNOT_EXECUTE = self.langBund.getString('system_cannot_execute') self.ERROR_NO_SNAPINS = 'No Exchange SnapIns Registered'
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() businessElementId = Framework.getDestinationAttribute('id') urlString = Framework.getDestinationAttribute('url') jobId = Framework.getDiscoveryJobId() dnsServers = Framework.getParameter('dnsServers') or None shell = None if dnsServers: dnsServers = [ dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip() ] or None if dnsServers: logger.debug('Using dns servers: ', dnsServers) if not urlString: msg = "There is no specified URL in the input BusinessElement CI" errormessages.resolveAndReport(msg, jobId, Framework) return OSHVResult try: bizOSH = modeling.createOshByCmdbIdString('business_element', businessElementId) OSHVResult.add(bizOSH) urlString = urlString[1:len(urlString) - 1] if netutils.isValidIp(urlString): productName = Framework.getDestinationAttribute('product') OSHVResult.add( scp.createScpOsh(bizOSH, 'tcp', urlString, 0, productName)) else: protocol, hostname, port, context = parseUrl(urlString) if not hostname: raise ValueError("Hostname is not defined in URL '%s'" % urlString) if not protocol: raise ValueError( "Failed to resolve the protocol from specified URL") shell = shellutils.ShellUtils( Framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) OSHVResult.addAll( scp.createScpOSHV(bizOSH, protocol, hostname, port, context, shell, dnsServers=dnsServers)) except ValueError, e: errormessages.resolveAndReport(e.message, jobId, Framework)
def runScanner(Framework): client = Framework.getConnectedClient() scannersConfigFile = Framework.getConfigFile( CollectorsConstants.SCANNERSBYPLATFORM_FILE_NAME) platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) architecture = Framework.getProperty( InventoryUtils.STATE_PROPERTY_ARCHITECTURE) logger.debug('Platform:', platform, ' architecture ', architecture) scannerPlatformConfig = scannersConfigFile.getPlatformConfiguration( platform, architecture) BASEDIR = Framework.getProperty( InventoryUtils.STATE_PROPERTY_RESOLVED_BASEDIR) lockValue = Framework.getProperty(LockUtils.ScannerNodeLock) client_options = LockUtils.getClientOptionsMap(client) logger.debug('Settings agent options') options = HashMap() options.put(InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, '') options.put(LockUtils.ScannerNodeLock, lockValue) options.put(InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED, str(System.currentTimeMillis())) logger.debug('Agent option ', InventoryUtils.AGENT_OPTION_DISCOVERY_SCANFILENAME, ':', '') logger.debug('Agent option ', LockUtils.ScannerNodeLock, ':', lockValue) logger.debug('Agent option ', InventoryUtils.STATE_PROPERTY_EXECUTION_STARTED, ':', str(System.currentTimeMillis())) filterOptionsByBlackList( client_options) #filter the options of client by black list client_options.putAll(options) client.setOptionsMap(client_options, 1) shell = shellutils.ShellUtils(client, skip_set_session_locale=True) shell.execCmd('cd ' + BASEDIR) runScannerCommand = scannerPlatformConfig.getRunScannerCommand() logger.debug('Launching scanner on remote machine') commandLine = runScannerCommand.getCommand() commandLine = updateCmdWithLogLevel(commandLine, Framework) commandLine = updateCmdForDeltaScanning(commandLine, Framework) commandLine = InventoryUtils.handleBaseDirPath(Framework, commandLine) commandLine = updateWithPrePostScriptCmd(Framework, commandLine) logger.debug('Scanner execution command:', commandLine) shell.execCmd(commandLine) logger.debug('Scanner Launched on remote machine') Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def open(self): client = None try: client = self.Framework.createClient() shell = shellutils.ShellUtils(client) fileContent = self.getFileContent(shell, self.fileName) bytes = self.getBytes(String(fileContent)) self.data = self.parseFileContent(bytes) finally: if client: client.close()
def getAgentConfigurationPath(Framework): platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM) architecture = Framework.getProperty( InventoryUtils.STATE_PROPERTY_ARCHITECTURE) if platform == "windows": client = Framework.getConnectedClient() shell = shellutils.ShellUtils(client) if not shell.is64BitMachine(): architecture = "x86" return getAgentConfigurationPathByPlatform(platform, architecture)
def __init__(self, framework, client, webseal_credentials_id, prefix=''): self.client = client self.framework = framework self.webseal_credentials_id = webseal_credentials_id self.shell = shellutils.ShellUtils(client) self.prefix = prefix self.binary_name = 'pdadmin' self.pdadmin_cmd = None if not client.isInteractiveAuthenticationSupported(): raise ValueError('Unsupported protocol') if self.shell.isWinOs(): self.enable_shell_proxy() self.setup_command() logger.debug('Using command %s ' % self.pdadmin_cmd)
def wrapper(framework): vector = ObjectStateHolderVector() framework = RichFramework(framework) creds_manager = CredsManager(framework) creds = get_credentials_fn(framework, creds_manager) if creds is None: return vector first_cred = take(0, 1, creds) if not first_cred: logger.reportErrorObject( _create_missed_creds_error(proto_name)) else: connection_exs = [] discovery_exs = [] warnings = [] at_least_once_discovered = False oshs = [] creds = list(itertools.chain(first_cred, creds)) if with_dns_resolver: local_client = framework.createClient( LOCAL_SHELL_PROTOCOL_NAME) local_shell = shellutils.ShellUtils(local_client) dns_resolver = _get_dns_resolver(local_shell) for args in starmap( functools.partial(cred_to_client_args, creds_manager), creds): try: with create_client(framework, *args) as client: args = with_dns_resolver and ( dns_resolver, ) + args or args oshs_, warnings_ = main_fn(client, framework, *args) oshs.extend(oshs_) warnings.extend(warnings_) at_least_once_discovered = True if stop_on_first: break except ConnectionException, ce: logger.debugException(str(ce)) connection_exs.append(ce) except (DiscoveryException, Exception), de: logger.debugException(str(de)) discovery_exs.append(de)
def resolveHostIpWithRemoteDns(self, hostName, remoteDns): """ Resolves (or not) IP address by given machine name using nslookup command on probe machine @param hostName: the machine name to resolve IP @type hostName: string @param remoteDns: the remate DNS name (or IP) to resolve host IP @type remoteDns: string @rtype: string """ if not self.localShell: self.localShell = shellutils.ShellUtils(self.getLocalShell()) if self.localShell: resolver = DNSResolver(self.localShell) return resolver.resolveHostIp(hostName, dnsServer=remoteDns)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() logger.debug(" ###### Connecting to EView client") logger.info (os.getenv('COMPUTERNAME')) codePage = Framework.getCodePage() properties = Properties() properties.put(BaseAgent.ENCODING, codePage) localshell = None try: client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) localshell = shellutils.ShellUtils(client, properties, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) except Exception, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME, Framework) logger.error(exInfo)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() # which is needed when running a remote command involving special characters properties = Properties() codePage = Framework.getDestinationAttribute('codepage') if (codePage != None) and (codePage != 'NA'): properties.setProperty( BaseAgent.ENCODING, codePage) properties.setProperty('QUOTE_CMD', 'true') shellUtils = None try: shellUtils = shellutils.ShellUtils(Framework, properties) except Exception, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, resolveProtocol(shellUtils, Framework), Framework)
def StepMain(Framework): consumers = Framework.getProperty(DependenciesDiscoveryConsts.NEXT_HOP_PROVIDERS_RESULT_PROPERTY) OSHVResult = ObjectStateHolderVector() if (consumers is not None) and (consumers.size() > 0): ipPortconcepts = HashMap() localShell = None try: dnsServers = Framework.getParameter('dnsServers') or None if dnsServers: dnsServers = [dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip()] or None localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) #going through extracted consumers for i in range(0, consumers.size()): consumer = consumers.get(i) depedencies = consumer.getDependencies() #going through dependencies of consumer for depedency in depedencies: variables = depedency.getExportVariables() #going through extracted variables of dependency for variable in variables: variableName = variable.getName() values = variable.getValues() conceptDefinition = variableName.split('.') if (len(conceptDefinition) == 2) and len(conceptDefinition[0]) and ((conceptDefinition[1].upper() == PROVIDER_IP) or (conceptDefinition[1].upper() == PROVIDER_PORT)): processIpPortConcept(ipPortconcepts, conceptDefinition[0].upper(), conceptDefinition[1].upper(), values) elif variableName.upper() == PROVIDER_IP: processIps(Framework, OSHVResult, values, localShell, dnsServers) resolveIpFromDnsPortipPortconcepts(Framework, OSHVResult, ipPortconcepts, localShell, dnsServers) Framework.sendObjects(OSHVResult) Framework.flushObjects() except: Framework.reportError(logger.prepareJythonStackTrace('')) Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE) if localShell is not None: try: localShell.close() localShell = None except: pass Framework.getState().setProperty(DependenciesDiscoveryConsts.NEXT_HOP_PROVIDERS_RESULT_PROPERTY, not OSHVResult.isEmpty()) Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def DiscoveryMain(Framework): """ @type Framework: com.hp.ucmdb.discovery.probe.services.dynamic.core.DynamicServiceFrameworkImpl """ OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') hostId = Framework.getDestinationAttribute('hostId') shell = None try: client = Framework.createClient() shell = shellutils.ShellUtils(client) except Exception, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, Framework)
def getDiscovererByShell(client, Framework, shell=None): if shell is None: shell = shellutils.ShellUtils(client) if shell.isWinOs(): tcpDiscoverer = TCPDisByWinShell(client, shell, Framework) return tcpDiscoverer else: uname = client.executeCmd('uname') if uname: for pattern, discovererClass in _PATTERN_TO_TCP_DISCOVERER_BY_SHELL.items( ): if re.search(pattern, uname): tcpDiscoverer = discovererClass(client, shell, uname, Framework) return tcpDiscoverer logger.debug('OS is not supported: %s' % uname)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') WEBSERVER_ID = Framework.getDestinationAttribute('id') HOST_ID = Framework.getDestinationAttribute('hostId') protocolName = errormessages.protocolNames.get(protocol) or protocol logger.debug('started siebel WSE (eapps.cfg) discovery using ', protocol, ' protocol') shellUtils = None try: client = Framework.createClient() shellUtils = shellutils.ShellUtils(client) except JavaException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, Framework)
def restoreSWUtilizationConfiguration(Framework): InventoryUtils.releaseConnection(Framework) # Framework.setConnectedClient(None) InventoryUtils.acquireConnection(Framework) # try to restore ini files if existed BASEDIR = AgentPlatformParameters.getAgentConfigurationPath(Framework) pluginIniFile = Framework.getProperty("local_plugin_temp_file") discusgeIniFile = Framework.getProperty("local_discusge_temp_file") pluginIniFileSuccess = 1 if pluginIniFile and not InventoryUtils.copyLocalFileToRemote( Framework, pluginIniFile, BASEDIR + "plugin.tni", 0): pluginIniFileSuccess = 0 Framework.reportWarning( "restore plugin.ini file failed, will use default configuration") discusgeIniFileSuccess = 1 if discusgeIniFile and not InventoryUtils.copyLocalFileToRemote( Framework, discusgeIniFile, BASEDIR + "discusge.tni", 0): discusgeIniFileSuccess = 0 Framework.reportWarning( "restore discusge.ini file failed, will use default configuration") client = Framework.getConnectedClient() shell = shellutils.ShellUtils(client, skip_set_session_locale=True) if pluginIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD( Framework, BASEDIR, "plugin.tni", "plugin.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) if discusgeIniFileSuccess: renameCMD = AgentPlatformParameters.getRenameCMD( Framework, BASEDIR, "discusge.tni", "discusge.ini") logger.debug(renameCMD) shell.execCmd(renameCMD) File(pluginIniFile).delete() File(discusgeIniFile).delete() Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') hostCmdbId = Framework.getDestinationAttribute('hostId') managedSystemCmdbId = Framework.getDestinationAttribute('managedSystemId') osType = Framework.getDestinationAttribute('osType') client = None shell = None hostOsh = modeling.createOshByCmdbId('host', hostCmdbId) managedSystemOsh = modeling.createOshByCmdbId('ibm_pseries_frame', managedSystemCmdbId) try: client = Framework.createClient() shell = shellutils.ShellUtils(client) OSHVResult = doDiscovery(shell, hostOsh, managedSystemOsh, Framework, osType) except Exception, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, Framework)
def DiscoveryMain(Framework): protocolName = Framework.getDestinationAttribute('Protocol') OSHVResult = ObjectStateHolderVector() try: HOST_IP = Framework.getDestinationAttribute('ip_address') MANAGER_PORT = Framework.getParameter('port') shellUtils = None try: codePage = Framework.getCodePage() properties = Properties() properties.put( BaseAgent.ENCODING, codePage) shellUtils = shellutils.ShellUtils(Framework, properties) discoveredOracleHomes = [] if shellUtils.isWinOs(): discoveredOracleHomes = OracleIASOracleHomeWindowsDiscoverer(shellUtils).discover() else: discoveredOracleHomes = OracleIASOracleHomeDiscoverer(shellUtils).discover() logger.debug('Discovered Oracle Homes from the running processes: %s' % discoveredOracleHomes) for oracleHomePath in discoveredOracleHomes: pathExists = 0 if oracleHomePath and oracleHomePath.strip(): try: opmnXML = shellUtils.safecat(str(oracleHomePath) + '/opmn/conf/opmn.xml') parseOpmnXml(opmnXML, HOST_IP, oracleHomePath, MANAGER_PORT, shellUtils, OSHVResult, Framework) pathExists = 1 except: logger.debugException('') if not pathExists: Framework.reportWarning("Can't retrieve opmn.xml content.") if OSHVResult.size() == 0: Framework.reportError("Failed to discover Oracle AS") finally: shellUtils and shellUtils.closeClient() except JavaException, ex: logger.debugException('') errormessages.resolveAndReport(ex.getMessage(), protocolName, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') hostId = Framework.getDestinationAttribute('hostId') virshPath = Framework.getParameter('virsh_path') prepareVirshPathList(virshPath) try: shell = None try: client = Framework.createClient() shell = shellutils.ShellUtils(client) rootServerOsh = modeling.createOshByCmdbId('host_node', hostId) OSHVResult.addAll(doDicovery(shell, Framework, rootServerOsh)) finally: try: shell and shell.closeClient() except: logger.debugException("") logger.error("Unable to close shell") except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocol, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') ipList = Framework.getTriggerCIDataAsList('ip_address') hostId = Framework.getDestinationAttribute('id') hostOSH = modeling.createOshByCmdbId('host', hostId) clientShUtils = None errorsList = [] warningsList = [] #the job triggered on windows with more than one IP, so at least two IP available #so we can connect to cluster IP and communicate with some other machine #in that case we have to check is connected IP a cluster IP and reconnect by dedicated one for ip in ipList: try: props = Properties() props.setProperty(CollectorsConstants.DESTINATION_DATA_IP_ADDRESS, ip) client = Framework.createClient(props) clientShUtils = shellutils.ShellUtils(client) discoveryNLB(clientShUtils, OSHVResult, hostOSH, Framework, ip) errorsList = [] warningsList = [] break except ConnectedToClusterIpException: try: clientShUtils and clientShUtils.closeClient() except: logger.debugException("") logger.error('Unable to close shell') clientShUtils = None except NoNlbControlUtilityException, ex: logger.reportWarning('No NLB control utility found') break except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndAddToObjectsCollections( strException, protocol, warningsList, errorsList)
def getHostNames(ip_string, Framework=None, dnsServers=None): localShell = None hostname = None aliasList = [] try: if Framework: localShell = shellutils.ShellUtils( Framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) hostname, aliasList = getHostNamesFromShell(ip_string, localShell, dnsServers) except: logger.warnException("Cannot get hostnames for %s" % ip_string) if localShell: try: localShell.close() localShell = None except: pass return hostname, aliasList
def DiscoveryMain(Framework): ip = Framework.getDestinationAttribute("ip") or None port = Framework.getDestinationAttribute("https_port") or None hostCmdbId = Framework.getDestinationAttribute("host_id") or None oshvector = ObjectStateHolderVector() hostOsh = modeling.createOshByCmdbIdString('node', hostCmdbId.strip()) if not (hostOsh and ip and port): logger.error("Incorrect input data: %s" % hostCmdbId.strip()) logger.reportError("Incorrect input data") return oshvector localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) dnsResolver = dns_resolver.FallbackResolver([dns_resolver.SocketDnsResolver(), dns_resolver.NsLookupDnsResolver(localShell)]) hosts = dnsResolver.resolve_hostnames(ip) logger.debug("Host names to check: %s" % hosts) errors = [] discoverResult = {} for hostname in hosts: try: logger.info("Getting certificate from %s:%s" % (hostname, port)) certificates = ssl_cert_discoverer.openSslSession(hostname, port, ssl_cert_discoverer.discoverCertificates) if certificates: logger.info("Got %s certificates" % len(certificates)) discoverResult[hostname] = certificates else: logger.warn("There are no any certificates on the %s:%s" % (hostname, port)) logger.reportError("There are no any certificates on the target host") except JException,ex: logger.debugException(ex.getMessage()) errors.append(ex.getMessage()) except Exception, ex: logger.debugException(ex.message) errors.append(ex.message)
def getIPs(hostname, Framework=None, dnsServers=None): if netutils.isValidIp(hostname): return [hostname] localShell = None ips = [] try: if Framework: localShell = shellutils.ShellUtils( Framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)) ips = getIPsFromShell(hostname, localShell, dnsServers) except: logger.warnException("Cannot get IPs for %s" % hostname) if localShell: try: localShell.close() localShell = None except: pass return ips
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') protocolName = errormessages.protocolNames.get(protocol) or protocol try: shellClient = None try: client = Framework.createClient() shellClient = shellutils.ShellUtils(client) discoverCluster(shellClient, protocolName, Framework, OSHVResult) finally: try: shellClient and shellClient.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JavaException, ex: strException = ex.getMessage() errormessages.resolveAndReport(strException, protocolName, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ipAddress = Framework.getDestinationAttribute('ip_address') credentialsId = Framework.getDestinationAttribute('credentialsId') hostId = Framework.getDestinationAttribute('hostId') hostOsh = modeling.createOshByCmdbIdString('host', hostId) PROTOCOL_NAME = 'PowerShell' try: client = Framework.createClient() shell = shellutils.ShellUtils(client) discoverer = None try: for discovererClass in [ msexchange_win_shell.Exchange2007Discoverer, msexchange_win_shell.Exchange2010Discoverer ]: try: discoverer = discovererClass(shell) exchangeServers = discoverer.discover() for exchangeServer in exchangeServers: topoBuilder = msexchange.TopologyBuilder( exchangeServer, hostOsh, ipAddress, credentialsId) OSHVResult.addAll(topoBuilder.build()) break except msexchange_win_shell.AddSnapInException: logger.warn('Failed to import Snap-In.') discoverer = None if not discoverer: raise Exception( "Failed to discover MS-Exchange. See Logs for details.") finally: shell.closeClient() except JavaException, ex: logger.debugException('') strException = str(ex.getMessage()) errormessages.resolveAndReport(strException, PROTOCOL_NAME, Framework)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() path = Framework.getDestinationAttribute('path') fileName = Framework.getDestinationAttribute('fileName') shellUtils = None try: shellUtils = shellutils.ShellUtils(Framework) if shellUtils.isWinOs(): pathAndFile = path + '\\' + fileName else: pathAndFile = path + '/' + fileName except: logger.errorException('Failed to initialize client') else: try: tnsFile = shellUtils.safecat(pathAndFile) TNSNamesParsingLib.doReadFile(shellUtils, pathAndFile, OSHVResult, tnsFile) except: logger.debugException('Unexpected doReadFile() Exception:') if shellUtils: shellUtils.closeClient() return OSHVResult