def DiscoveryMain(framework, credsManager): config = ( flow.DiscoveryConfigBuilder(framework). dest_data_required_params_as_str('Protocol').dest_data_params_as_str( language=None).bool_params(discoverUnknownIPs=False).params( DNSServerName=None, DNSServerDomain=None, )).build() warnings = [] with closing(_createClient(framework, config.Protocol)) as client: shell = shellutils.ShellFactory().createShell(client) dnsServerAddress = config.DNSServerName domain = config.DNSServerDomain if not (domain and dnsServerAddress): logger.info("DNS Server address or domain is not specified. " "Determine automatically") dnsServerAddress, domain = getServerAndDomain( framework, client, config) discoverer = dns_discoverer.createDiscovererByShell( shell, dnsServerAddress) types = (dns.ResourceRecord.Type.A, ) # @UndefinedVariable records = discoverer.transferZone(dns.Zone(domain), *types) logger.info("Found %s records" % len(records)) oshs = _reportHosts(records, config.discoverUnknownIPs) return oshs, warnings return [], warnings
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() shell = None protocol = Framework.getDestinationAttribute('Protocol') switchId = Framework.getDestinationAttribute('hostId') print "Switch id %s" % switchId errorMessage = None try: client = Framework.createClient() try: shellFactory = shellutils.ShellFactory() shell = shellFactory.createShell(client) switchOsh = modeling.createOshByCmdbId('switch', switchId) discoverer = NexusDiscoverer(Framework, shell, '', '', '', '') discoverer.discoverInterfacesAndIps() interfaces_dict = discoverer.hostDataObject.interfaces ports_map = parsePorts(interfaces_dict.values()) vlan_discoverer = layer2_shell_discoverer.VlanDiscoverer(shell) vlans = vlan_discoverer.discoverVlans() layer2_discoverer = layer2_shell_discoverer.Layer2Discoverer(shell) remote_peers_map = layer2_discoverer.discover() OSHVResult.addAll(layer2.reportTopology(switchOsh, interfaces_dict, vlans, remote_peers_map, ports_map)) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell') except JException, ex: errorMessage = ex.getMessage()
def DiscoveryMain(Framework): ipAddress = Framework.getDestinationAttribute('ip_address') shell = None try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) f5Discoverer = createF5Discoverer(shell, ipAddress) f5Discoverer.discover() return f5Discoverer.getTopology() except NoF5Exception: logger.reportWarning("No F5 LTM found on the remote machine") except: errorMsg = 'Failed to get general information' errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION, ['shell', 'general information'], errorMsg) logger.debugException(errorMsg) logger.reportWarningObject(errobj) finally: try: shell and shell.closeClient() except: logger.debugException('') logger.error('Unable to close shell')
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) # Image Id -> Image OSH imageDict = dict() # Container Id -> Container OSH containerDict = dict() # Container Id -> linked Container Id containerLinks = dict() # Node from Trigger nodeId = Framework.getTriggerCIData('hostId') nodeOSH = modeling.createOshByCmdbIdString("node", nodeId) OSHVResult.add(nodeOSH) # Trigger CI Running Software docker daemon dockerId = Framework.getTriggerCIData("triggerId") dockerDaemonOSH = modeling.createOshByCmdbIdString("docker_daemon", dockerId) OSHVResult.add(dockerDaemonOSH) # Docker version for docker daemon versionOutput = shell.execCmd('docker -v') if shell.getLastCmdReturnCode() == 0: dockerDaemonOSH.setAttribute('version', versionOutput.strip()) else: Framework.reportError('Failed in command: docker version.') #Get Filesystem filesystemDict = dict() skipDockerVolume = getFilesystem(shell, filesystemDict) # Docker dockerOSH = ObjectStateHolder('docker') dockerOSH.setAttribute('name', 'Docker') dockerOSH.setContainer(nodeOSH) OSHVResult.add(dockerOSH) dockerDaemonLink = modeling.createLinkOSH('membership', dockerOSH, dockerDaemonOSH) OSHVResult.add(dockerDaemonLink) dockerNodeLink = modeling.createLinkOSH('dependency', dockerOSH, nodeOSH) OSHVResult.add(dockerNodeLink) discoverDockerImage(shell, imageDict, nodeOSH, OSHVResult, Framework) discoverDockerContainer(shell, skipDockerVolume, filesystemDict, containerDict, containerLinks, imageDict, dockerDaemonOSH, nodeOSH, client, Framework, OSHVResult) return OSHVResult
def DiscoveryMain(Framework): Framework = jee_connection.EnhancedFramework(Framework) platform = jee.Platform.WEBLOGIC try: # establish connection client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) # prepare components for topology discoverer fs = file_system.createFileSystem(shell) processDiscoverer = process_discoverer.getDiscovererByShell(shell) except (Exception, JException), exc: logger.warnException(str(exc)) jee_connection.reportError(Framework, str(exc), platform.getName())
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') protocolName = errormessages.protocolNames.get(protocol) or protocol hostId = Framework.getDestinationAttribute('hostId') isSuccessfull = 1 try: client = None try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) triggerConfigs = emc_autostart_discover.createTriggerConfigs( Framework) logger.debug("Found %d configurations" % len(triggerConfigs)) topology = None for triggerConfig in triggerConfigs: try: layout = emc_autostart_discover.createLayout(shell) discoverer = emc_autostart_discover.createDiscoverer( shell, Framework, layout) topology = discoverer.discover(triggerConfig) if topology is not None: reporter = emc_autostart_report.createAutoStartReporter( Framework, hostId) resultsVector = reporter.report(topology) OSHVResult.addAll(resultsVector) break except emc_autostart_discover.NoApplicationFoundException, ex: msg = "Skipping configuration %r, reason: %s" % ( triggerConfig, str(ex)) logger.warn(msg) finally: client and client.close() except emc_autostart_discover.InsufficientPermissionsException, ex: msg = "Command execution failed due to insufficient permissions" errormessages.resolveAndReport(msg, protocolName, Framework) isSuccessfull = 0 logger.error( "Failed to execute '%s' command due to insufficient permissions, verify sudo/credentials configuration" % str(ex))
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() codePage = Framework.getCodePage() props = Properties() props.setProperty(BaseAgent.ENCODING, codePage) shell = None try: client = Framework.createClient(props) shell = shellutils.ShellFactory().createShell(client) dnsResolver = dns_resolver.NsLookupDnsResolver(shell) language = shell.osLanguage logger.debug("Using '%s' language bundle" % language.bundlePostfix) bundle = shellutils.getLanguageBundle('langMsCluster', language, Framework) clusterCmd = ms_cluster_discoverer.createClusterCmd(shell, bundle) if clusterCmd.isUsingCmd(): bundle = clusterCmd.detectLangBandle(Framework) clusterCmd.setBundle(bundle) vector.addAll(_discoverTopology(clusterCmd, bundle, dnsResolver)) except NoInstanceFound: errobj = errorobject.createError( errorcodes.MS_CLUSTER_INSTANCES_NOT_FOUND, None, 'MS cluster instances not found in discovery') logger.reportWarningObject(errobj) except: msg = str(sys.exc_info()[1]) logger.debugException(msg) if (msg.lower().find('timeout') > -1): errobj = errorobject.createError( errorcodes.CONNECTION_TIMEOUT_NO_PROTOCOL, None, 'Connection timed out - reactivate with larger timeout value') logger.reportErrorObject(errobj) logger.debugException('Connection timed out') else: errobj = errormessages.resolveError(msg, 'ntcmd') logger.reportErrorObject(errobj) logger.errorException(msg) try: shell and shell.closeClient() except: logger.debugException() logger.error("Unable to close shell") return vector
def DiscoveryMain(Framework): Framework = jee_connection.EnhancedFramework(Framework) platform = jee.Platform.WEBSPHERE shell = None try: try: # ======================= Establish connection ===================== client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) # create FS fs = _createFileSystemRecursiveSearchEnabled( file_system.createFileSystem(shell)) pathUtil = file_system.getPath(fs) except (Exception, JException), exc: logger.warnException(str(exc)) jee_connection.reportError(Framework, str(exc), platform.getName()) else:
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): ipAddress = Framework.getDestinationAttribute('ip_address') discoveredPorts = Framework.getParameter('ports') or None useNMap = Framework.getParameter('useNMap') == 'true' nmapPath = Framework.getParameter('nmapPath') or None scanUDP = Framework.getParameter('scanUDP') == 'true' UDPports = Framework.getParameter('UDPports') or None UDPports = UDPports and UDPports.strip() connectTimeOut = int(Framework.getParameter('connectTimeOut')) #if we need to check host's reachability: if Framework.getParameter('checkIfIpIsReachable').lower() == 'true': if not netutils.pingIp(Framework, ipAddress, Framework.getParameter('pingTimeOut')): logger.debug('Could not connect to ', ipAddress, ' by ping') msg = 'Target host is not reachable' warningObject = errorobject.createError( errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS, ['', msg], msg) logger.reportWarningObject(warningObject) return OSHVResult = ObjectStateHolderVector() hostOsh = modeling.createHostOSH(ipAddress) OSHVResult.add(hostOsh) cfgFile = Framework.getConfigFile( CollectorsParameters.KEY_COLLECTORS_SERVERDATA_PORTNUMBERTOPORTNAME) onlyKnownPorts = Framework.getParameter('checkOnlyKnownPorts') onlyKnownPorts = (onlyKnownPorts and onlyKnownPorts.lower() == 'true') portsList = getPorts(discoveredPorts and discoveredPorts.strip(), PortType.TCP, cfgFile, onlyKnownPorts) if scanUDP: if onlyKnownPorts and not UDPports: UDPports = '*' portsList.extend( getPorts(UDPports, PortType.UDP, cfgFile, onlyKnownPorts)) portsToDiscover = filter(lambda port: port.isDiscover, portsList) isConnectedPortFound = False useFallback = False if useNMap: # Nmap flow supports udp and tcp ports client = Framework.createClient( ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) try: shell = shellutils.ShellFactory().createShell(client) fs = file_system.createFileSystem(shell) try: if nmapPath and fs.isDirectory(nmapPath): path_tool = NtPath() nmapPath = path_tool.join(nmapPath, nmap.NMAP_EXECUTABLES[1]) except PathNotFoundException: logger.warn("Specified directory \"%s\" is not exists." % nmapPath) if nmapPath and not nmap.NmapPathValidator.get(fs).validate( nmapPath): logger.warn( "Specified Nmap path \"%s\" is not exists. Trying the system path..." % nmapPath) nmapPath = None nmapDiscover = nmap.getByShell(shell, nmapPath) nmapVersion = nmapDiscover.getVersion() if not nmapVersion: raise Exception('Cannot get nmap version') logger.debug("Found nmap %s" % nmapVersion) nmapVersion = float(nmapVersion) if nmapVersion < 5.21: raise Exception("Not supported version of nmap found.") tcpPorts = [ port.getPortNumber() for port in portsToDiscover if port and port.getProtocolName() == 'tcp' and port.isIpInRange(ipAddress) ] udpPorts = [ port.getPortNumber() for port in portsToDiscover if port and port.getProtocolName() == 'udp' and port.isIpInRange(ipAddress) ] discoveredPorts = nmapDiscover.doPortScan(ipAddress, tcpPorts, udpPorts) portsNameByPortInfo = {} for port in portsToDiscover: port_names = portsNameByPortInfo.setdefault( (port.getProtocol(), port.getPortNumber()), []) port_names.append(port.portName) if discoveredPorts: isConnectedPortFound = True for port_info in discoveredPorts: port_names = portsNameByPortInfo.get(port_info, []) OSHVResult.addAll( reportPort(hostOsh, ipAddress, port_names, *port_info)) except: logger.debugException( "Nmap executing failed. Try to use default behavior...") logger.reportWarning("Nmap executing failed") useFallback = True if useFallback or not useNMap: # Old flow supports only TCP ports for port in portsToDiscover: if port.isIpInRange(ipAddress): if port.getProtocol() == PortType.UDP.getProtocol(): logger.warn( "UDP port scan is not supporting by default behavior. Skipping..." ) elif port.getProtocol() == PortType.TCP.getProtocol() and ( netutils.checkTcpConnectivity( ipAddress, port.getPortNumber(), connectTimeOut)): OSHVResult.addAll( reportPort(hostOsh, ipAddress, [port.portName], port.getProtocol(), port.getPortNumber())) #we found one connected port -> we need to add hostOsh to OSHVResult isConnectedPortFound = True #in case we didn't find any port, return nothing if not isConnectedPortFound: OSHVResult.clear() msg = 'None of specified ports were discovered on destination host' warningObject = errorobject.createError( errorcodes.CONNECTION_FAILED_NO_PROTOCOL_WITH_DETAILS, ['', msg], msg) logger.reportWarningObject(warningObject) return OSHVResult
shellType, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError( errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [shellType], msg) errorsList.append(errobj) if not client: Framework.clearState() else: # successfully connected, do discovery clientType = client.getClientType() connectedOSCredentialID = None try: try: shellFactory = shellutils.ShellFactory() shell = shellFactory.createShell(client, clientType) connectedOSCredentialID = ConnectedOSCredentialFinder.findCredential( Framework, shell, client, errorsList, warningsList) # If we got a default value, we just pass None later # Else - we need to signal the existing client which can be only UDA by now that it has a credential # to take sudo password from, if it needs it if (not connectedOSCredentialID or connectedOSCredentialID == ConnectedOSCredentialFinder.NO_CONNECTED_CRED_ID): connectedOSCredentialID = None else: try: client.setConnectedShellCredentialID( connectedOSCredentialID)
def DiscoveryMain(Framework): vector = ObjectStateHolderVector() protocol = Framework.getDestinationAttribute('Protocol') client = None shell = None try: try: # connect to destination client = Framework.createClient() # wrap client with Shell shell = shellutils.ShellFactory().createShell(client) except AuthenticationException, ae: errormessages.resolveAndReport(ae.getMessage(), protocol, Framework) except: exInfo = logger.prepareJythonStackTrace('') errormessages.resolveAndReport(exInfo, protocol, Framework) else: language = Framework.getDestinationAttribute('language') hostCmdbId = Framework.getDestinationAttribute('hostId') # configure internationalization support if language and language != 'NA': langBund = Framework.getEnvironmentInformation().getBundle( 'langHost_Resources_By_TTY', language) else: langBund = Framework.getEnvironmentInformation().getBundle( 'langHost_Resources_By_TTY') # discovery discoverCPUs = Boolean.parseBoolean( Framework.getParameter('discoverCPUs')) discoverDisks = Boolean.parseBoolean( Framework.getParameter('discoverDisks')) discoveriSCSIInfo = Boolean.parseBoolean( Framework.getParameter('discoveriSCSIInfo')) discoverDrivers = Boolean.parseBoolean( Framework.getParameter('discoverDrivers')) discoverMemory = Boolean.parseBoolean( Framework.getParameter('discoverMemory')) discoverSoftware = Boolean.parseBoolean( Framework.getParameter('discoverInstalledSoftware')) discoverUsers = Boolean.parseBoolean( Framework.getParameter('discoverUsers')) discoverServices = Boolean.parseBoolean( Framework.getParameter('discoverServices')) discoverShares = Boolean.parseBoolean( Framework.getParameter('discoverShares')) discoverP2P = Boolean.parseBoolean( Framework.getParameter('discoverP2P')) try: hostOsh = modeling.createOshByCmdbIdString('host', hostCmdbId) if discoverShares: try: vector.addAll(_discoverSharedResources(shell, hostOsh)) except: errorMessage = 'Failed to discover shared resources' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['share', protocol], errorMessage) if discoverCPUs: try: vector.addAll( TTY_HR_CPU_Lib.disWinOS(hostCmdbId, shell, Framework, langBund)) except: errorMessage = 'Failed to discover CPUs' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['cpus', protocol], errorMessage) if discoverDisks: try: vector.addAll(TTY_HR_Disk_Lib.disWinOS(hostOsh, shell)) except: errorMessage = 'Failed to discover disks' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['disks', protocol], errorMessage) if discoverDrivers and shell.isWinOs(): try: vector.addAll( _discoverWindowsDeviceDriver(shell, hostOsh)) except: errorMessage = 'Failed to discover windows device driver by powershell' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['windows device driver', protocol], errorMessage) if discoveriSCSIInfo: try: vector.addAll( TTY_HR_Disk_Lib.disWinOSiSCSIInfo(hostOsh, shell)) except: errorMessage = 'Failed to discover iSCSI info' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['iSCSI', protocol], errorMessage) if discoverMemory: try: vector.addAll( TTY_HR_Memory_Lib.disWinOS(hostCmdbId, shell, Framework, langBund)) except: errorMessage = 'Failed to discover memory' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['memory', protocol], errorMessage) processes = [] try: processesDiscoverer = process_discoverer.DiscovererByShellOnWindows( shell) processes = processesDiscoverer.discoverAllProcesses() if not processes: raise ValueError() except: errorMessage = 'Failed to discover processes' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['processes', protocol], errorMessage) if processes: # save processes to DB process_discoverer.saveProcessesToProbeDb( processes, hostCmdbId, Framework) # report processes discoverProcesses = Boolean.parseBoolean( Framework.getParameter('discoverProcesses')) if discoverProcesses: processReporter = process.Reporter() for processObject in processes: processVector = processReporter.reportProcess( hostOsh, processObject) vector.addAll(processVector) if discoverUsers: try: vector.addAll(_discoverUsers(hostOsh, shell)) except: errorMessage = 'Failed to discover users' _logWarn( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['users', protocol], errorMessage) cmdLineToInstalledSoftware = {} softNameToInstSoftOSH = {} if discoverSoftware: try: softwareOSHs = TTY_HR_Software_Lib.disWinOS( hostCmdbId, shell, Framework, langBund, softNameToInstSoftOSH) if softwareOSHs: vector.addAll(softwareOSHs) except: errorMessage = 'Failed to discover installed software' _logWarn(errorcodes.FAILED_DISCOVERING_RESOURCE, ['installed software', protocol], errorMessage) servicesByCmd = Hashtable() if discoverServices: try: srvcOSHs = NTCMD_HR_REG_Service_Lib.doService( shell, hostOsh, servicesByCmd, langBund, Framework) vector.addAll(srvcOSHs) except: errorMessage = 'Failed to discover services' _logWarn(errorcodes.FAILED_DISCOVERING_RESOURCE, ['services', protocol], errorMessage) connectivityEndPoints = [] try: tcpDiscoverer = Dis_TCP.getDiscovererByShell( client, Framework, shell) if tcpDiscoverer is not None: tcpDiscoverer.discoverTCP() connectivityEndPoints = tcpDiscoverer.getProcessEndPoints( ) except: errorMessage = 'Failed to run TCP discovery' _logWarn( errorcodes.FAILED_RUNNING_DISCOVERY_WITH_CLIENT_TYPE, ['tcp', protocol], errorMessage) appSign = applications.createApplicationSignature( Framework, client, shell) if processes: appSign.setProcessesManager( applications.ProcessesManager(processes, connectivityEndPoints)) servicesInfo = applications.ServicesInfo(servicesByCmd) appSign.setServicesInfo(servicesInfo) softwareInfo = applications.InstalledSoftwareInfo( cmdLineToInstalledSoftware, softNameToInstSoftOSH) appSign.setInstalledSoftwareInfo(softwareInfo) appSign.getApplicationsTopology(hostCmdbId) if discoverP2P: try: p2p = process_to_process.ProcessToProcess(Framework) p2p.getProcessesToProcess() except: errorMessage = 'Failed to run p2p discovery' _logWarn(errorcodes.FAILED_RUNNING_DISCOVERY, ['p2p', protocol], errorMessage) except JException, ex: exInfo = ex.getMessage() errormessages.resolveAndReport(exInfo, protocol, Framework) except:
def DiscoveryMain(Framework): """ Retrieving a list of LDAP ports we strive to connect to domain controller in member role first. So we have to choose the lowest port number in the list. """ protocolName = "LDAP" OSHVResult = ObjectStateHolderVector() baseDn = Framework.getParameter('baseDN') or None if baseDn == 'NA': baseDn = None ipAddress = Framework.getDestinationAttribute('ip_address') credentialsId = Framework.getDestinationAttribute('credentials_id') applicationPort = Framework.getDestinationAttribute("application_port") serviceAddressPort = Framework.getDestinationAttribute('port') if not applicationPort or applicationPort == 'NA': applicationPort = serviceAddressPort # build environment and connect envBuilder = active_directory_utils.LdapEnvironmentBuilder(applicationPort) client = Framework.createClient(credentialsId, envBuilder.build()) discoverer = oracle_ldap_discoverer.OracleLdapDiscoverer(client, baseDn) try: probe_client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME) probe_shell = shellutils.ShellFactory().createShell(probe_client) resolver = netutils.FallbackResolver([netutils.JavaDnsResolver(), netutils.DnsResolverByShell(probe_shell)]) # discover servers = discoverer.discover() # report endpoint_builder = netutils.ServiceEndpointBuilder() endpoint_reporter = netutils.EndpointReporter(endpoint_builder) oracle_builder = db_builder.Oracle() reporter = db.OracleTopologyReporter(oracle_builder, endpoint_reporter) for dbServer in servers: if dbServer: try: address = dbServer.address if not ip_addr.isValidIpAddress(address): ips = resolver.resolveIpsByHostname(address) if ips and len(ips) > 0: dbServer.address = str(ip_addr.IPAddress(ips[0])) # get Host OSH if not (dbServer.address and netutils.isValidIp(address) and not netutils.isLocalIp(address)): raise ValueError("Address for the specified server is not valid or is local") hostOsh = modeling.createHostOSH(dbServer.address) # report database OSHVResult.addAll(reporter.reportServerAndDatabases(dbServer, hostOsh)) # report TNS Listener listener = db.OracleListener(dbServer.address, dbServer.getPort()) OSHVResult.addAll(reporter.reportTnsListener(listener, hostOsh)) # report Oracle Service Names if dbServer.getServiceNames(): OSHVResult.addAll(reporter.reportServiceNameTopology(dbServer.getServiceNames(), listener.getOsh(), dbServer.getOsh())) except netutils.ResolveException: logger.error("Cannot resolve " + dbServer.address + ". Skip") except oracle_ldap_discoverer.OracleContextDiscoveryException, ex: msg = str(ex) logger.debugException(msg) logger.error(msg)
def shell(client): return shellutils.ShellFactory().createShell(client)
def localshell(localclient): return shellutils.ShellFactory().createShell(localclient)
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): SHELL_CLIENT_PROTOCOLS = _getSupportedShellProtocols(Framework) ip = Framework.getDestinationAttribute('ip_address') domain = Framework.getDestinationAttribute('ip_domain') codepage = Framework.getCodePage() useLastState = Framework.getParameter('useLastSuccessConnection') vector = ObjectStateHolderVector() warningsList = [] errorsList = [] # preparing empty dictionary for storing credentials later credentialsByType = {} # take the latest used credentials if any lastState = None if useLastState and useLastState.lower() == 'true': lastState = Framework.loadState() if lastState: credentialsByType[None] = [lastState] # try to get ip address by mac address from ARP Cache macAddress = Framework.getDestinationAttribute('ip_mac_address') foundIp = clientdiscoveryutils.getIPAddressOnlyFromMacAddress(macAddress) if foundIp: ip = foundIp # Gather credentials for protocols for clientType in SHELL_CLIENT_PROTOCOLS: # getting an ordered list of credentials for the given client type and storing them in the credentials dictionary protocols = netutils.getAvailableProtocols(Framework, clientType, ip, domain) if protocols: credentialsByType[clientType] = protocols ########################################################################################################## ##################################Start Special processing for Universal Discovery Agent################## # take Universal Discovery Agent credentials if new Universal Discovery Agent installed on that IP connectedDDMAgentCredentials = None if useLastState and useLastState.lower() == 'true': connectedDDMAgentCredentials = Framework.loadGlobalState(ip) client = None udaNotAlive = 0 if connectedDDMAgentCredentials: logger.debug('Found global state credentials ', connectedDDMAgentCredentials, ' of installed agent on ip:', ip) client = createClient(Framework, ClientsConsts.DDM_AGENT_PROTOCOL_NAME, [connectedDDMAgentCredentials], ip, codepage, warningsList, errorsList) # If we are successfully connected if client: logger.debug('Succeeded to connect with global state credentials ', client.getCredentialId(), ' of installed agent') Framework.saveState(client.getCredentialId()) else: logger.debug('Failed to connect with global state credentials ', connectedDDMAgentCredentials, ' on ip:', ip) udaNotAlive = 1 #AgentUtils.clearGlobalState(Framework) # only for case where no connection established before if not client: # checks whether there are credential for specified protocol if credentialsByType: if lastState: client = createClientFromLastState(Framework, lastState, warningsList, errorsList) if not client: logger.debug( 'Failed to create client using last state properties. Will try to connect using other credentials.' ) if not client: for clientType in SHELL_CLIENT_PROTOCOLS: credentials = credentialsByType.get(clientType) if credentials: client = createClient(Framework, clientType, credentials, ip, codepage, warningsList, errorsList) if client: warningsList = [] errorsList = [] # save credentials id for further reuse Framework.saveState(client.getCredentialId()) break else: for shellType in SHELL_CLIENT_PROTOCOLS: msg = errormessages.makeErrorMessage( shellType, pattern=errormessages.ERROR_NO_CREDENTIALS) errobj = errorobject.createError( errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [shellType], msg) warningsList.append(errobj) if not client: Framework.clearState() else: # successfully connected, do discovery shell = None clientType = client.getClientType() connectedOSCredentialID = None try: try: shellFactory = shellutils.ShellFactory() shell = shellFactory.createShell(client, clientType) connectedOSCredentialID = ConnectedOSCredentialFinder.findCredential( Framework, shell, client, errorsList, warningsList) # If we got a default value, we just pass None later # Else - we need to signal the existing client which can be only UDA by now that it has a credential # to take sudo password from, if it needs it if (not connectedOSCredentialID or connectedOSCredentialID == ConnectedOSCredentialFinder.NO_CONNECTED_CRED_ID): connectedOSCredentialID = None else: try: client.setConnectedShellCredentialID( connectedOSCredentialID) except: logger.warn( 'Failed to setConnectedShellCredentialID, sudo commands may not work in this run' ) vector.addAll( doDiscovery(Framework, shell, client, ip, codepage, connectedOSCredentialID)) except (Exception, JException), jex: msg = str(jex) logger.debugException(msg) errormessages.resolveAndAddToObjectsCollections( msg, clientType, warningsList, errorsList) finally: if udaNotAlive and client: logger.debug('find another shell can be connected. ', shell) logger.debug( 'Removing the connected uda shell because it failed to connect' ) agentOsh = ObjectStateHolder( ClientsConsts.DDM_AGENT_PROTOCOL_NAME) agentOsh.setAttribute('application_ip', ip) agentOsh.setAttribute('data_name', ClientsConsts.DDM_AGENT_PROTOCOL_NAME) #agentOsh.setAttribute('application_port', shell.getPort()) agentOsh.setContainer(modeling.createHostOSH(ip)) Framework.deleteObject(agentOsh) Framework.flushObjects() Framework.clearGlobalState(ip) if shell: try: shell.closeClient() except: errobj = errorobject.createError( errorcodes.CLIENT_NOT_CLOSED_PROPERLY, None, "Client was not closed properly") warningsList.append(errobj) logger.warnException('') # close client anyway if client and client.close(): pass # create shell OSH if connection established but discovery failed if not vector.size(): logger.warn( 'Discovery failed, though shell object will be created') hostOsh = modeling.createHostOSH(ip, filter_client_ip=True) if hostOsh: languageName = None langBund = Framework.getEnvironmentInformation().getBundle( 'langNetwork', languageName) shellOsh = createShellObj( client, client, ip, langBund, languageName, codepage, connectedShellCredId=connectedOSCredentialID) shellOsh.setContainer(hostOsh) vector.add(shellOsh) else: logger.warn( 'Failed to create node and shell since IP is of a Client range type, not enough data for reconciliation.' ) for errobj in warningsList: logger.reportWarningObject(errobj) for errobj in errorsList: logger.reportErrorObject(errobj) return vector
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() try: client = Framework.createClient() shell = shellutils.ShellFactory().createShell(client) reportHostName = Framework.getParameter('reportLparNameAsHostName') if not reportHostName: reportHostName = 'false' fsm_id = Framework.getDestinationAttribute('fsmId') fsm_osh = modeling.createOshByCmdbId('ibm_fsm', fsm_id) #do dsscovery part supported_types = ibm_fsm_discoverer.getAvailableSupportedEntityTypes( shell) logger.debug( 'Found following supported types %s. Will proceed to discovery' % supported_types) chassis_discoverer = ibm_fsm_discoverer.ChassisDiscoverer(shell) chassis = chassis_discoverer.discover() #logger.debug('Discovered chassis %s' % chassis) farm_discoverer = ibm_fsm_discoverer.FarmDiscoverer(shell) farms = farm_discoverer.discover() server_discoverer = ibm_fsm_discoverer.ServerDiscoverer(shell) servers, vms = server_discoverer.discover() #logger.debug('Discovered servers %s' % servers) #logger.debug('Discovered vms %s' % vms) system_pool_discoverer = ibm_fsm_discoverer.SystemPoolDiscoverer(shell) system_pools = system_pool_discoverer.discover() switch_discoverer = ibm_fsm_discoverer.SwitchDiscoverer(shell) switches = switch_discoverer.discover() storage_discoverer = ibm_fsm_discoverer.StorageDiscoverer(shell) storages = storage_discoverer.discover() #logger.debug('Discovered storage systems %s ' % storages) managed_system_details_discoverer = ibm_fsm_discoverer.ManagedSystemDiscoverer( shell, servers) servers = managed_system_details_discoverer.discover() #lpar_details_discoverer = ibm_fsm_discoverer.LParDiscoverer(shell) #for server in servers: # server.lpars_dict = lpar_details_discoverer.discover(server.managedSystem) for server in servers: if not server.managedSystem: logger.debug( 'Skipping %s, since it is not fully discoverable.' % server) continue managedSystemName = server.managedSystem.genericParameters.name '''Command will fail on the target device if its state is 'Incomplete', skip them''' if server.managedSystem.genericParameters.state == 'Incomplete': continue server.managedSystem.lparProfilesDict = ibm_fsm_discoverer.LParDiscoverer( shell).discover(server.managedSystem) server.managedSystem.cpuPoolList = ibm_fsm_discoverer.ProcessorPoolDiscoverer( shell).discover(managedSystemName) server.managedSystem.vScsiList = ibm_fsm_discoverer.ScsiDiscoverer( shell).discover(managedSystemName) server.managedSystem.vEthList = ibm_fsm_discoverer.EthernetDiscoverer( shell).discover(managedSystemName) ibm_fsm_discoverer.discoverIoSlots(shell, servers) ibm_fsm_discoverer.discoverVirtIoSlots(shell, servers) #do topology reporting OSHVResult = ibm_fsm.ReportTopology(chassis, servers, system_pools, vms, switches, storages, fsm_osh, reportHostName) except: logger.debugException('') logger.reportError('Failed to discover FSM see logs for details') return OSHVResult