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 config_provider(framework, connection_number): config = (flow.DiscoveryConfigBuilder(framework).dest_data_params_as_list( 'Protocol').dest_data_params_as_list( 'installpath').dest_data_required_params_as_str('sid'). dest_data_required_params_as_str('hanadb_cmdbid')).build() return config._replace(Protocol=config.Protocol[connection_number], installpath=config.installpath[connection_number])
def _build_config(framework, credsId, instNr, clientNr): '@types: Framework, str, str, str -> DiscoveryConfigBuilder' envInformation = framework.getEnvironmentInformation() return (flow.DiscoveryConfigBuilder(framework).dest_data_params_as_str( ip_address=None, hostname=None).value(domain=envInformation.getProbeManagerDomain(), credsId=credsId, instNr=instNr, clientNr=clientNr).build())
def _build_config(framework): return (flow.DiscoveryConfigBuilder(framework) .dest_data_params_as_str(instance_number=None, connection_client=None, credentialsId=None, system_name=None, ip_address=None) .bool_params(discoverRFCConnections=False, discoverSAPProfiles=False, reportComponentsAsConfigFile=True)).build()
def isam_with_ipse_config_provider(framework, connection_number): config = (flow.DiscoveryConfigBuilder(framework).dest_data_params_as_list( 'isam_ids').dest_data_params_as_str(Protocol='httpprotocol').params( pdadmin_api_query='pdadmin', management_authentication_api_query='management_authentication', firmware_settings_api_query='firmware_settings', reverseproxy_api_query='reverseproxy', )).build() return config
def get_isam_with_ipse_cred_combinations(framework, cred_manager): ip_addresses = get_isam_with_ipse_case_ips(framework) cred_ids = cred_manager.get_creds_for_destination('httpprotocol') config = (flow.DiscoveryConfigBuilder(framework).dest_data_params_as_list( 'credentials_id')).build() tcid_creds = filter(None, config.credentials_id) cred_ids = list(tcid_creds) + list(set(cred_ids) - set(tcid_creds)) return zip(cred_ids, ip_addresses)
def getCredentialId(framework): config = (flow.DiscoveryConfigBuilder(framework) .dest_data_params_as_list( # generic application server instance and client numbers 'instance_number', 'connection_client') .dest_data_required_params_as_str('ip_address') .build()) framework = flow.RichFramework(framework) creds_manager = flow.CredsManager(framework) cred_args = _getCredsArgsForTopologyJob(creds_manager, config) cred_args = _makeSetOfSystemNamesAsLastArgument(cred_args, set()) first_ = first(cred_args) if first_ is None: return None else: return chain((first_,), cred_args)
def config_provider(framework, connection_number): config = ( flow.DiscoveryConfigBuilder( framework).dest_data_required_params_as_str( 'name').dest_data_required_params_as_str('cmdbid'). dest_data_required_params_as_str( 'container_cmdbid').dest_data_required_params_as_str( 'ip_address').dest_data_required_params_as_str('credential_id') .dest_data_params_as_str(Protocol='httpprotocol').params( pdadmin_api_query='pdadmin', management_authentication_api_query='management_authentication', firmware_settings_api_query='firmware_settings', reverseproxy_api_query='reverseproxy', )).build() return config
def decorator(framework): config = (flow.DiscoveryConfigBuilder(framework) .dest_data_params_as_list( # generic application server instance and client numbers 'sapas_instance', 'sapas_client', # central service instance and client numbers 'sapcs_instance', 'sapcs_client', # message server ports 'sap_port') .dest_data_required_params_as_str('ip_address') .build()) framework = flow.RichFramework(framework) creds_manager = flow.CredsManager(framework) cred_args = _getCredsArgsForConnectionJob(creds_manager, config) cred_args = _makeSetOfSystemNamesAsLastArgument(cred_args, set()) stop_on_first = False return iterate_over_args(main_fn, framework, cred_args, JCO_PROTOCOL_NAME, stop_on_first)
def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() client = None framework = StatisticsFramework(Framework) try: try: client = framework.createClient() except: # No need to report twice, exception msg is sufficient # errobj = errorobject.createError(errorcodes.CONNECTION_FAILED_NO_PROTOCOL, None, 'Connection failed') # logger.reportErrorObject(errobj) errMsg = 'Exception while creating %s client: %s' % ( ClientsConsts.SNMP_PROTOCOL_NAME, sys.exc_info()[1]) errormessages.resolveAndReport(str(sys.exc_info()[1]), ClientsConsts.SNMP_PROTOCOL_NAME, framework) logger.debugException(errMsg) else: config = (flow.DiscoveryConfigBuilder( framework).dest_data_required_params_as_str('ip_address'). dest_data_params_as_list('host_ips')).build() ipaddress = config.ip_address host_ips = filter(None, config.host_ips) ips = set(host_ips) ips.add(ipaddress) hostId = framework.getDestinationAttribute('hostId') hostOsh = modeling.createOshByCmdbIdString('host', hostId) discoverUsers = Boolean.parseBoolean( framework.getParameter('discoverUsers')) if discoverUsers: logger.debug('Starting to discover users') try: snmp_dis_user_lib.doQueryOSUsers(client, OSHVResult) except: errobj = errorobject.createError( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['users', 'snmp'], 'Failed to discover users by snmp') logger.reportWarningObject(errobj) logger.errorException('Failed to discover users by snmp') discoverDisks = Boolean.parseBoolean( framework.getParameter('discoverDisks')) if discoverDisks: logger.debug('Starting to discover disks') try: snmp_dis_disk_lib.doQueryDisks(client, OSHVResult) except: errobj = errorobject.createError( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['disks', 'snmp'], 'Failed to discover disks by snmp') logger.reportWarningObject(errobj) logger.errorException('Failed to discover disks by snmp') discoverProcesses = Boolean.parseBoolean( framework.getParameter('discoverProcesses')) processes = [] logger.debug('Starting to discover processes') try: processDiscoverer = process_discoverer.getDiscovererBySnmp( client) processes = processDiscoverer.discoverAllProcesses() if not processes: raise ValueError() except: errobj = errorobject.createError( errorcodes.FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['processes', 'snmp'], 'Failed to discover processes by snmp') logger.reportWarningObject(errobj) logger.errorException('Failed to discover processes by snmp') if processes: # save processes to DB process_discoverer.saveProcessesToProbeDb( processes, hostId, framework) # report processes if discoverProcesses: processReporter = process.Reporter() for processObject in processes: processesVector = processReporter.reportProcess( hostOsh, processObject) OSHVResult.addAll(processesVector) discoverServices = Boolean.parseBoolean( framework.getParameter('discoverServices')) if discoverServices: logger.debug('Starting to discover services') try: snmp_dis_service_lib.doQuerySNMPService(client, OSHVResult) except: errobj = errorobject.createError( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['services', 'snmp'], 'Failed to discover services by snmp') logger.reportWarningObject(errobj) logger.errorException( 'Failed to discover services by snmp') discoverSoftware = Boolean.parseBoolean( framework.getParameter('discoverInstalledSoftware')) if discoverSoftware: logger.debug('Starting to discover software') try: snmp_dis_software_lib.doQuerySoftware(client, OSHVResult) except: errobj = errorobject.createError( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['software', 'snmp'], 'Failed to discover software by snmp') logger.reportWarningObject(errobj) logger.errorException( 'Failed to discover software by snmp') connectivityEndPoints = [] try: tcpDiscoverer = Dis_TCP.TCPDisBySNMP(client, framework, ips=tuple(ips)) if tcpDiscoverer is not None: tcpDiscoverer.discoverTCP() connectivityEndPoints = tcpDiscoverer.getProcessEndPoints() except: errorMessage = 'Failed to run tcp discovery by snmp' logger.debugException(errorMessage) errobj = errorobject.createError( errorcodes.FAILED_RUNNING_DISCOVERY_WITH_CLIENT_TYPE, ['tcp', 'snmp'], errorMessage) logger.reportWarningObject(errobj) if processes: appSign = applications.createApplicationSignature( framework, client) appSign.setProcessesManager( applications.ProcessesManager(processes, connectivityEndPoints)) appSign.getApplicationsTopology(hostId) discoverModules = Boolean.parseBoolean( framework.getParameter('discoverModules')) if discoverModules: logger.debug('Begin discover snmp modules...') try: from snmp_model_finder import SnmpStateHolder from snmp_model_finder import SnmpQueryHelper from snmp_model_finder import ModelTypeMatcher import snmp_model_discovery snmpStateHolder = SnmpStateHolder() cacheClient = None # from discovery.client.snmp import SnmpClientCacheProxy # cacheClient = SnmpClientCacheProxy(client, 'cache/'+ipaddress+'.cache') snmpQueryHelper = SnmpQueryHelper(client) mtm = ModelTypeMatcher(snmpStateHolder, snmpQueryHelper) logger.debug('The target is matched:', mtm.match()) logger.debug('The type of the target is:', snmpStateHolder.getTypes()) vector = snmp_model_discovery.discoverAll( hostOsh, snmpStateHolder, snmpQueryHelper) logger.debug('Discovered CI count:', vector.size()) OSHVResult.addAll(vector) if cacheClient: cacheClient.writeCache() except: errobj = errorobject.createError( errorcodes. FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['modules', 'snmp'], 'Failed to discover modules by snmp') logger.reportWarningObject(errobj) logger.errorException('Failed to discover modules by snmp') logger.debug('End discover snmp modules') finally: if client != None: client.close() if OSHVResult.size() == 0 and framework.getSentObjectsCount() == 0: logger.reportWarning('SNMP: No data collected') return OSHVResult
def get_ipse_only_ips(framework): config = flow.DiscoveryConfigBuilder(framework).dest_data_params_as_list( 'ipse_only_ips').build() ips = filter(None, config.ipse_only_ips) return ips