def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()	
	ipAddress = Framework.getDestinationAttribute('ip_address')
	credentialsId = Framework.getDestinationAttribute('credentialsId')
	hostId = Framework.getDestinationAttribute('hostId')
	
	hostOsh = ms_exchange_utils.restoreHostById(hostId)
	hostName = Framework.getDestinationAttribute('hostName')	
	if not hostName or hostName == 'N/A':
		hostName = ms_exchange_utils.getHostNameFromWmi(Framework)
	
	if not hostName:
		errobj = errorobject.createError(errorcodes.FAILED_GETTING_INFORMATION_NO_PROTOCOL, ['host name'], 'Failed to obtain host name')
		logger.reportErrorObject(errobj)
		return
	
	props = Properties()
	props.put(AgentConstants.PROP_WMI_NAMESPACE, WMI_NAMESPACE)	
	try:
		wmiClient = Framework.createClient(props)
		wmiAgent = WmiAgent(wmiClient, Framework)
		try:
			discoverExchangeServer(wmiAgent, ipAddress, credentialsId, OSHVResult, Framework, hostOsh, hostName)
		finally:			
			wmiClient.close()
	except Exception, ex:
		message = ex.getMessage()
		if (re.search("Invalid\sclass", message)):
			message = 'Unable to get Exchange data from WMI'
		logger.debugException(message)
		errormessages.resolveAndReport(message, WMI_PROTOCOL, Framework)
Ejemplo n.º 2
0
def iterate_over_args(main_fn, framework, cred_args, proto_name, stop_on_first):
    '''
    @param cred_args: parameters you decided to iterate over
    '''
    vector = ObjectStateHolderVector()
    framework = flow.RichFramework(framework)
    creds_manager = flow.CredsManager(framework)
    # as cred_args possibly generator or iterator, realize only first
    first_ = first(cred_args)
    if first_ is None:
        logger.reportErrorObject(flow._create_missed_creds_error(proto_name))
    else:
        # restore cred_args
        cred_args = chain((first_,), cred_args)
        connection_exs = []
        discovery_exs = []
        warnings = []
        at_least_once_discovered = False
        for args in cred_args:
            try:
                oshs, warnings_ = main_fn(framework, creds_manager, *args)
                warnings.extend(warnings_ or ())
                vector.addAll(oshs)
                at_least_once_discovered = True
                if stop_on_first:
                    break
            except flow.ConnectionException, ce:
                logger.debugException(str(ce))
                connection_exs.append(ce)
            except (flow.DiscoveryException, Exception, JException), de:
                logger.debugException(str(de))
                discovery_exs.append(de)
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    host_id =  Framework.getDestinationAttribute('hostId')
    errorsList = []
    
    protocol = "ldap"
    credential_ids = Framework.getAvailableProtocols(ip, protocol)
    lastConnectedCredential = Framework.loadState()
    lastConnectedCredential and credential_ids.append(lastConnectedCredential)
    
    if not credential_ids:
        msg = errormessages.makeErrorMessage('webseal', pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, ['webseal'], msg)
        errorsList.append(errobj)
    
    client = Framework.createClient()
    credential_id = find_valid_credential(credential_ids, client, Framework)
        
    if credential_id:
        Framework.saveState(credential_id)
        OSHVResult.addAll(reportWebSeal(host_id, credential_id))
    else:
        Framework.clearState()
        msg = errormessages.makeErrorMessage('Shell', pattern=errormessages.ERROR_FAILED_TO_CONNECT_TO_SERVER)
        errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, ['webseal'], msg)
        errorsList.append(errobj)
        
    for errobj in errorsList:
        logger.reportErrorObject(errobj)
    
    return OSHVResult
Ejemplo n.º 4
0
def iterate_over_creds(main_fn, proto_name, stop_on_first=True,
                       is_cred_ok_fn=identity):
    '''
    Decorator for the DiscoveryMain function in case when connection attempts
    performed over available protocols

    @param main_fn: DiscoveryMain function reference
    @param proto_name: protocol to connect with
    @param stop_on_first: Stop on first successful discovery
    @param is_cred_ok_fn: predicate to check whether credentials are suitable
            Signature is (Framework, CredsManager, str -> bool)

    Usage:

        from fptools import paritallyApply as Fn, _ as __
        @Fn(iterate_over_creds, __, ClientsConsts.SSH_PROTOCOL_NAME)
        def DiscoveryMain(rich_framework, creds_manager, cred_id):
            '@types: Framework, CredsManager, str -> list[osh], list[str]'
            ...
            return oshs, warnings

    '''
    @wraps(main_fn)
    def decorator(framework):
        vector = ObjectStateHolderVector()
        framework = RichFramework(framework)
        creds_manager = CredsManager(framework)
        creds = creds_manager.get_creds_for_destination(proto_name)
        creds = filter(Fn(is_cred_ok_fn, framework, creds_manager, __), creds)
        if not creds:
            logger.reportErrorObject(_create_missed_creds_error(proto_name))
        else:
            connection_exs = []
            discovery_exs = []
            warnings = []
            at_least_once_discovered = False
            for cred_id in creds:
                try:
                    oshs, warnings = main_fn(framework, creds_manager, cred_id)
                    vector.addAll(oshs)
                    at_least_once_discovered = True
                    if stop_on_first:
                        break
                except ConnectionException, ce:
                    logger.debugException(str(ce))
                    connection_exs.append(ce)
                except (DiscoveryException, Exception, JException), de:
                    logger.debugException(str(de))
                    discovery_exs.append(de)

            if at_least_once_discovered:
                if warnings:
                    each(logger.reportWarning, warnings)
            else:
                for ex in connection_exs:
                    obj = _create_connection_errorobj(proto_name, ex.message)
                    logger.reportWarningObject(obj)
                for ex in discovery_exs:
                    obj = _create_discovery_errorobj(proto_name, ex.message)
                    logger.reportErrorObject(obj)
Ejemplo n.º 5
0
    def decorator_fn(original_fn):
        @wraps(original_fn)
        def wrapper(framework):
            client_factories_provider = kwargs.get('client_factories_provider')
            if not client_factories_provider:
                client_factories_provider = default_client_factories_provider
            proto_name = kwargs.get('protocol_name')
            stop_on_first = kwargs.get('stop_on_first')

            vector = ObjectStateHolderVector()
            framework = RichFramework(framework)
            if not proto_name:
                proto_name = framework.get_dest_attribute('Protocol')

            creds_manager = CredsManager(framework)
            client_factories = client_factories_provider(framework,
                                                         creds_manager)

            first_factory = take(0, 1, client_factories)
            if not first_factory:
                logger.reportErrorObject(_create_missed_creds_error(proto_name))
            else:
                connection_exs = []
                discovery_exs = []
                warnings = []
                at_least_once_discovered = False
                oshs = []

                client_factories = list(itertools.chain(first_factory, client_factories))

                main_fn = original_fn
                for index, client_factory in enumerate(client_factories):
                    try:
                        with client_factory() as client:
                            args_ = (framework, client, index)
                            kwargs_ = {}
                            oshs_, warnings_ = main_fn(*args_, **kwargs_)

                            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)

                if at_least_once_discovered:
                    each(logger.reportWarningObject, warnings)
                else:
                    for ex in connection_exs:
                        obj = _create_connection_errorobj(proto_name, ex.message)
                        logger.reportWarningObject(obj)
                    for ex in discovery_exs:
                        obj = _create_discovery_errorobj(proto_name, ex.message)
                        logger.reportErrorObject(obj)
                vector.addAll(oshs)
Ejemplo n.º 6
0
    def decorator_fn(original_fn):
        @wraps(original_fn)
        def wrapper(framework):
            client_factories_provider = kwargs.get('client_factories_provider')
            if not client_factories_provider:
                client_factories_provider = default_client_factories_provider
            proto_name = kwargs.get('protocol_name')
            stop_on_first = kwargs.get('stop_on_first')

            vector = ObjectStateHolderVector()
            framework = RichFramework(framework)
            if not proto_name:
                proto_name = framework.get_dest_attribute('Protocol')

            creds_manager = CredsManager(framework)
            client_factories = client_factories_provider(framework,
                                                         creds_manager)

            first_factory = take(0, 1, client_factories)
            if not first_factory:
                logger.reportErrorObject(_create_missed_creds_error(proto_name))
            else:
                connection_exs = []
                discovery_exs = []
                warnings = []
                at_least_once_discovered = False
                oshs = []

                client_factories = list(itertools.chain(first_factory, client_factories))

                main_fn = original_fn
                for index, client_factory in enumerate(client_factories):
                    try:
                        with client_factory() as client:
                            args_ = (framework, client, index)
                            kwargs_ = {}
                            oshs_, warnings_ = main_fn(*args_, **kwargs_)

                            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)

                if at_least_once_discovered:
                    each(logger.reportWarningObject, warnings)
                else:
                    for ex in connection_exs:
                        obj = _create_connection_errorobj(proto_name, ex.message)
                        logger.reportWarningObject(obj)
                    for ex in discovery_exs:
                        obj = _create_discovery_errorobj(proto_name, ex.message)
                        logger.reportErrorObject(obj)
                vector.addAll(oshs)
Ejemplo n.º 7
0
def iterate_over_args(main_fn, framework, cred_args, proto_name,
                      stop_on_first):
    '''
    @param cred_args: parameters you decided to iterate over
    '''
    vector = ObjectStateHolderVector()
    framework = flow.RichFramework(framework)
    creds_manager = flow.CredsManager(framework)
    # as cred_args possibly generator or iterator, realize only first
    first_ = first(cred_args)
    if first_ is None:
        logger.reportErrorObject(flow._create_missed_creds_error(proto_name))
    else:
        # restore cred_args
        cred_args = chain((first_, ), cred_args)
        connection_exs = []
        discovery_exs = []
        warnings = []
        at_least_once_discovered = False
        for args in cred_args:
            try:
                oshs, warnings_ = main_fn(framework, creds_manager, *args)
                warnings.extend(warnings_ or ())
                vector.addAll(oshs)
                at_least_once_discovered = True
                if stop_on_first:
                    break
            except flow.ConnectionException, ce:
                logger.debugException(str(ce))
                connection_exs.append(ce)
            except (flow.DiscoveryException, Exception, JException), de:
                logger.debugException(str(de))
                discovery_exs.append(de)
Ejemplo n.º 8
0
 def decorator(framework):
     vector = ObjectStateHolderVector()
     framework = RichFramework(framework)
     creds_manager = CredsManager(framework)
     creds = creds_manager.get_creds_for_destination(proto_name)
     creds = filter(Fn(is_cred_ok_fn, framework, creds_manager, __), creds)
     if not creds:
         logger.reportErrorObject(_create_missed_creds_error(proto_name))
     else:
         connection_exs = []
         discovery_exs = []
         warnings = []
         at_least_once_discovered = False
         for cred_id in creds:
             try:
                 oshs, warnings = main_fn(framework, creds_manager, cred_id)
                 vector.addAll(oshs)
                 at_least_once_discovered = True
                 if stop_on_first:
                     break
             except ConnectionException, ce:
                 logger.debugException(str(ce))
                 connection_exs.append(ce)
             except (DiscoveryException, Exception, JException), de:
                 logger.debugException(str(de))
                 discovery_exs.append(de)
def DiscoveryMain(Framework):
    resultVector = ObjectStateHolderVector()

    ipAddress = Framework.getDestinationAttribute(DestinationProperty.IP_ADDRESS)
    credentialsId = Framework.getDestinationAttribute(DestinationProperty.CREDENTIALS_ID)
    hypervisorCmdbId = Framework.getDestinationAttribute(DestinationProperty.HYPERVISOR_CMDB_ID)
    esxCmdbId = Framework.getDestinationAttribute(DestinationProperty.ESX_CMDB_ID)
    esxBiosUuid = Framework.getDestinationAttribute(DestinationProperty.ESX_BIOS_UUID)
    
    if not esxBiosUuid:
        msg = "ESX BIOS UUID from trigger data is empty"
        errorObject = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
        logger.error(msg)
        return resultVector
    
    try:
        unitaryComputerSystem = discoverEsxInventory(ipAddress, credentialsId, esxBiosUuid, Framework)
        
        inventoryResultVector = reportEsxInventory(unitaryComputerSystem, esxCmdbId)
        resultVector.addAll(inventoryResultVector)
        
        virtualMachines = discoverEsxVirtualTopology(ipAddress, credentialsId, esxBiosUuid, Framework)
        if virtualMachines:
            virtualResultVector = reportVirtualTopology(virtualMachines, hypervisorCmdbId)
            resultVector.addAll(virtualResultVector)
        
    except JException, ex:
        msg = ex.getMessage()
        msg = cim_discover.translateErrorMessage(msg)
        logger.debug(msg)
        errormessages.resolveAndReport(msg, cim.Protocol.DISPLAY, Framework)
Ejemplo n.º 10
0
def getPolicyContent(httpClient, ip, protocolId, protocolName, version):
    try:
        protocol = ProtocolManager.getProtocolById(protocolId)
        protocol_port = protocol.getProtocolAttribute('protocol_port')
        http_protocol = protocol.getProtocolAttribute('protocol')
        builder = oam_policy_builder.PolicyBuilder(http_protocol, ip, protocol_port, version, httpClient)
        return builder.createPolicyDoc()
    except JException, e:
        msg = 'URL is not accessable: ' + e.getMessage()
        errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolName], msg)
        logger.reportErrorObject(errobj)
Ejemplo n.º 11
0
def DiscoveryMain(Framework):

    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    codepage = Framework.getCodePage()

    shell = None
    credentialId = None
    OSHVResult = None
    warningsList = []
    errorsList = []

    protocolType = PowerShell.PROTOCOL_TYPE
    credentials = []
    # use the latest used credentials if any
    lastConnectedCredential = Framework.loadState()
    lastConnectedCredential and credentials.append(lastConnectedCredential)
    # and other defined for triggered IP
    credentials.extend(
        netutils.getAvailableProtocols(Framework, protocolType, ip, domain))
    if credentials:
        shell, credentialId = getShellUtils(Framework, protocolType,
                                            credentials, ip, codepage,
                                            warningsList, errorsList)
    else:
        msg = errormessages.makeErrorMessage(
            protocolType, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolType], msg)
        errorsList.append(errobj)

    if shell:
        # successfully connected, do discovery
        errorsList = []
        warningsList = []
        Framework.saveState(credentialId)
        OSHVResult = doDiscovery(Framework, shell, ip, credentialId, codepage,
                                 protocolType, warningsList, errorsList)
    else:
        if not len(errorsList):
            msg = errormessages.makeErrorMessage(
                protocolType, pattern=errormessages.ERROR_CONNECTION_FAILED)
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED,
                                             [protocolType], msg)
            errorsList.append(errobj)
        Framework.clearState()

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    return OSHVResult
Ejemplo n.º 12
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip_address = Framework.getTriggerCIDataAsList('ip_address')
    ip_domain = Framework.getTriggerCIDataAsList('ip_domain')
    credentialIds = Framework.getAvailableProtocols(ip_address[0], ProtocolManager.UDDI_REGISTRY)
    logger.debug('Len of credentials: %s' %str(len(credentialIds)))
    logger.debug('Start on Address:', ip_address[0], ',  Domain:', ip_domain[0])

    if credentialIds.__len__() == 0:
        msg = errormessages.makeErrorMessage(ProtocolManager.UDDI_REGISTRY, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [ProtocolManager.UDDI_REGISTRY], msg)
        logger.reportErrorObject(errobj)

    ip_domain = Framework.getDestinationAttribute("ip_domain")
    for credentialId in credentialIds:
        url = Framework.getProtocolProperty(credentialId, CollectorsConstants.UDDI_PROTOCOL_ATTRIBUTE_URL, '')
        if url == '':
            Framework.reportError('URL attribute is not specified in the UDDI protocol')
            continue

        # Check the URL
        try:
            logger.debug("Checking availability of %s" % url)
            netutils.doHttpGet(url, 20000, 'header').strip()
        except:
            Framework.reportWarning('Failed to connect to UDDI Registry using URL: ' + url)
            logger.debugException("Cannot connect to UDDI server")
        else:
            properties = Properties()
            properties.setProperty(CollectorsConstants.UDDI_PROTOCOL_ATTRIBUTE_URL, url)
            properties.setProperty("ip_domain", ip_domain)

            connected = False
            version = 0
            for uddiVersion in (3, 2):
                if connected:
                    break
                try:
                    logger.debug('Using version UDDIv%d' % uddiVersion)
                    properties.setProperty('uddi_version', str(uddiVersion))
                    logger.debug('Try to connect to UDDI Registry using url: ', url)
                    Framework.getAgent(AgentConstants.UDDI_AGENT, '', credentialId, properties)
                    logger.debug('Connected to UDDI Registry  url: ', url)
                    connected = True
                    version = uddiVersion
                except MissingSdkJarException, ex:
                    Framework.reportError('UDDI SDK jars are missed. Refer documentation for details')
                    logger.debugException(ex.getMessage())
                    break
                except JException, java_exc:
                    Framework.reportWarning("Cannot connect to UDDI server")
                    logger.debugException('Failed to connect to UDDI Registry: ' + java_exc.getMessage())
                except:
Ejemplo n.º 13
0
def createWmiClient(Framework, namespace=None):
    try:
        if namespace:
            props = Properties()
            props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, namespace)
            return Framework.createClient(props)
        else:
            return Framework.createClient()
    except:
        errobj = errorobject.createError(errorcodes.CONNECTION_FAILED_NO_PROTOCOL, ["WMI"], 'Failed to connect')
        logger.reportErrorObject(errobj)
        logger.debugException('Failed to to connect')
Ejemplo n.º 14
0
	def executeUpdate(self, sql):
		st = None
		try:
			try:
				st = self.conn.createStatement()
				return st.executeUpdate(sql)
			except:
				error = 'Failed to execute sql ' + sql
				logger.errorException(error)
				errobj = errorobject.createError(errorcodes.FAILED_TO_EXECUTE_SQL, [sql], error)
				logger.reportErrorObject(errobj)
		finally:
			self.closeStatement(st)
Ejemplo n.º 15
0
 def executeUpdate(self, sql):
     st = None
     try:
         try:
             st = self.conn.createStatement()
             return st.executeUpdate(sql)
         except:
             error = 'Failed to execute sql ' + sql
             logger.errorException(error)
             errobj = errorobject.createError(
                 errorcodes.FAILED_TO_EXECUTE_SQL, [sql], error)
             logger.reportErrorObject(errobj)
     finally:
         self.closeStatement(st)
Ejemplo n.º 16
0
def clientDiscovery(Framework, ip):
    (vec, errObj) = mainFunction(Framework, 1, ip)
    logger.debug('OSHVector contains ', vec.size(), ' objects.')
    if vec.size() == 0:
        logger.debug('Failed to connect or no valid protocols defined. No Host CI will be created')
        if (errObj == None or errObj.errMsg == None or errObj.errMsg.strip() == ''):
            altErr = errorobject.createError(errorcodes.INTERNAL_ERROR ,None , 'Discovery failed due to internal error')
            logger.reportErrorObject(altErr)
        else:
            logger.reportWarningObject(errObj)
    else:
        Framework.sendObjects(vec)
        Framework.flushObjects()
    return None
Ejemplo n.º 17
0
        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)
Ejemplo n.º 18
0
def createWmiClient(Framework, namespace=None):
    try:
        if namespace:
            props = Properties()
            props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, namespace)
            return Framework.createClient(props)
        else:
            return Framework.createClient()
    except:
        errobj = errorobject.createError(
            errorcodes.CONNECTION_FAILED_NO_PROTOCOL, ["WMI"],
            'Failed to connect')
        logger.reportErrorObject(errobj)
        logger.debugException('Failed to to connect')
Ejemplo n.º 19
0
    def getProcessesToProcess(self):
        if not self.shouldRun():
            return
        rs = None
        try:
            try:
                self.buildProcessMap()
                st = self.getPreparedStatement(ProcessToProcess.P2PSQL)

                logger.debug(st)
                rs = st.executeQuery()

                while(rs.next()):
                    SrcListen = rs.getBoolean('SrcListen')
                    DstListen = rs.getBoolean('DstListen')

                    if SrcListen and (not DstListen):
                        self.buildTcpConnTopology(rs, 'dst', 'src')
                    elif DstListen and (not SrcListen):
                        self.buildTcpConnTopology(rs, 'src', 'dst')
                    else:
                        srcPrefered = self.isPreferedService(rs, 'src')
                        dstPrefered = self.isPreferedService(rs, 'dst')
                        if srcPrefered and (not dstPrefered):
                            self.buildTcpConnTopology(rs, 'dst', 'src')
                        elif dstPrefered and (not srcPrefered):
                            self.buildTcpConnTopology(rs, 'src', 'dst')
                        else:
                            # we don't known which endpoint is listening,
                            # so we can't set the link direction
                            srcip = rs.getString('srcAddr')
                            srcport = rs.getInt('srcPort')
                            dstip = rs.getString('dstAddr')
                            dstport = rs.getInt('dstPort')
                            connString = '%s:%d %s:%d' % (srcip, srcport, dstip, dstport)
                            logger.warn('process to process topology: '
                                        'Listen endpoint is unknown, skipping %s' % connString)
            except:
                error = 'Failed to fetch processes to process communication'
                logger.errorException(error)
                errobj = errorobject.createError(errorcodes.PROCESS_TO_PROCESS_FAILED, None, error)
                logger.reportErrorObject(errobj)
        finally:
            if rs:
                try:
                    rs.close()
                except:
                    pass
            self.conn.close()
Ejemplo n.º 20
0
def DiscoveryMain(Framework):
    # get attribute
    shell = None
    client = None
    OSHVResult = ObjectStateHolderVector()

    try:
        ip = reportIpAddress(Framework, OSHVResult)

        # do host connection
        client, shell, warningsList, errorsList, hostOsh = host_connection.doConnection(Framework, ip, OSHVResult)

        if not (client and shell):
            logger.debug("host connection failed")
            for errobj in warningsList:
                logger.reportWarningObject(errobj)
            for errobj in errorsList:
                logger.reportErrorObject(errobj)
            return OSHVResult

        # do host application
        runningApplications, processes, connectivityEndPoints, connections, errorsList = host_application.doApplication(
            Framework, ip,
            OSHVResult,
            client, shell, hostOsh)

        if not (runningApplications and processes and connectivityEndPoints and connections):
            logger.debug("host application failed")
            for errobj in errorsList:
                logger.reportErrorObject(errobj)
            return OSHVResult


        # do next hop
        next_hop.doNextHop(Framework, ip, OSHVResult, shell, runningApplications,
                           processes, connectivityEndPoints, connections, hostOsh)

    finally:
        #close connection
        if shell:
            try:
                shell.closeClient()
            except:
                logger.warnException('Client was not closed properly')
                # close client anyway
        if client and client.close():
            pass

    return OSHVResult
Ejemplo n.º 21
0
    def decorator(framework):
        framework = flow.RichFramework(framework)
        proto_name = clients.SAPJmxClient.SAPJMX_CLIENT_TYPE
        versions = get_sap_java_client_versions()
        if not filter(len, versions):
            msg = 'SAP_JMX drivers are missing'
            obj = flow._create_connection_errorobj(proto_name, msg)
            logger.reportErrorObject(obj)
            return ObjectStateHolderVector()

        pairs = get_applicable_credentials(framework, P4_PORT_PATTERN)
        creds = ((creds_id, port, v) for creds_id, port in pairs
                                            for v in versions)
        return iterate_over_args(main_fn, framework, creds,
                                 proto_name, stop_on_first)
Ejemplo n.º 22
0
def DiscoveryMain(Framework):
    vector = ObjectStateHolderVector()

    (vec, warnList, errList) = WMI_Connection_Utils.mainFunction(Framework)
    logger.debug('OSHVector contains ', vec.size(), ' objects.')
    # just in case we couldnt do any connection
    if vec.size() == 0:
        for errobj in errList:
            logger.reportErrorObject(errobj)
        for errobj in warnList:
            logger.reportWarningObject(errobj)
    else:
        vector.addAll(vec)

    return vector
def DiscoveryMain(Framework):

    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    codepage = Framework.getCodePage()

    shell = None
    credentialId = None
    OSHVResult = None
    warningsList = []
    errorsList = []

    protocolType = PowerShell.PROTOCOL_TYPE
    credentials = []
    # use the latest used credentials if any
    lastConnectedCredential = Framework.loadState()
    lastConnectedCredential and credentials.append(lastConnectedCredential)
    # and other defined for triggered IP
    credentials.extend(netutils.getAvailableProtocols(Framework, protocolType,
                                                      ip, domain))
    if credentials:
        shell, credentialId = getShellUtils(Framework, protocolType,
                                            credentials, ip, codepage,
                                            warningsList, errorsList)
    else:
        msg = errormessages.makeErrorMessage(protocolType, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolType], msg)
        errorsList.append(errobj)

    if shell:
        # successfully connected, do discovery
        errorsList = []
        warningsList = []
        Framework.saveState(credentialId)
        OSHVResult = doDiscovery(Framework, shell, ip, credentialId, codepage, protocolType, warningsList, errorsList)
    else:
        if not len(errorsList):
            msg = errormessages.makeErrorMessage(protocolType, pattern=errormessages.ERROR_CONNECTION_FAILED)
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolType], msg)
            errorsList.append(errobj)
        Framework.clearState()

    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    return OSHVResult
Ejemplo n.º 24
0
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):
    resultVector = ObjectStateHolderVector()

    ipAddress = Framework.getDestinationAttribute(DestinationProperty.IP_ADDRESS)
    
    connectionHandler = vmware_cim_discover.DefaultDiscoveryConnectionHandler(Framework, discoverConnectedEsx)
    
    connectionDiscoverer = None
    try:
        connectionDiscoverer = vmware_cim_discover.ConnectionDiscoverer(Framework, connectionHandler)
    except (cim_discover.MissingConfigFileException, vmware_cim_discover.RuntimeException), ex:
        msg = str(ex)
        errorObject = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
        logger.error(msg)
        return resultVector
Ejemplo n.º 26
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute('ip')
    port = Framework.getDestinationAttribute('port')
    scp_id = Framework.getDestinationAttribute('scp_id')
    apache_id = Framework.getDestinationAttribute('apache_id')
    apache_ip = Framework.getDestinationAttribute('apache_ip')
    contexts = Framework.getTriggerCIDataAsList('contexts')
    context_ids = Framework.getTriggerCIDataAsList('context_ids')

    localShell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))
    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME
    connectionFailedMsgs = []
    protocolIds = findProperProtocolIds(ip, netutils.getAvailableProtocols(Framework, protocolName, ip) or [])

    if not protocolIds:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        logger.reportErrorObject(errobj)
        return OSHVResult

    httpClient, protocolId, version = findHttpProtocol(Framework, protocolName, protocolIds, ip, connectionFailedMsgs)
    if httpClient:
        apacheOsh = modeling.createOshByCmdbIdString('apache', apache_id)
        # create oam running software
        createOAMRunningSoftwareOsh(scp_id, ip, port, protocolId, version, apacheOsh, OSHVResult)
        # get oam policy content
        policy_content = getPolicyContent(httpClient, ip, protocolId, protocolName, version)
        # parse oam policy, get redirect urls
        authorization_policies = oam_policy_parser.parse_oam_policy(policy_content)
        redirect_policies = oam_policy_parser.get_redirect_policies(authorization_policies)
        # create oam dependency scp
        for index in range(0, len(contexts)):
            context, context_id = contexts[index], context_ids[index]
            if context_id:
                matched_policies = findMatchedRedirectPolicies(context, redirect_policies)
                apacheScpOsh = modeling.createOshByCmdbIdString('scp', context_id)
                for policy in matched_policies:
                    createOAMDependenyScp(localShell, apacheOsh, apacheScpOsh, policy.redirect_url, apache_ip, OSHVResult)

    if not OSHVResult.size():
        for msg in connectionFailedMsgs:
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED, [protocolName], msg)
            logger.reportErrorObject(errobj)

    return OSHVResult
Ejemplo n.º 27
0
        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)
Ejemplo n.º 28
0
	def insertEntitiesProbeDb(self, entitiesbulk):
		st = None
		try:
			try:
				sql = entitiesbulk[0].getInsertSQL()
				st = self.conn.prepareStatement(sql)
				for entity in entitiesbulk:
					entity.setValues(st)
					st.addBatch()
				st.executeBatch()
			except:
				error = 'Failed to add entities of type ' + str(entitiesbulk[0].getEntityType()) + ' to Probe database'
				logger.errorException(error)
				errobj = errorobject.createError(errorcodes.FAILED_ADDING_ENTITIES_TO_PROBE_DB, [str(entitiesbulk[0].getEntityType())], error)
				logger.reportErrorObject(errobj)
		finally:
			self.closeStatement(st)
Ejemplo n.º 29
0
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
Ejemplo n.º 30
0
def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()
	(vec, errObj) = NTCMD_Connection_Utils.mainFunction(Framework)

	logger.debug('OSHVector contains ', vec.size(), ' objects.')
	# just in case we couldn't do any connection
	if vec.size() == 0:
		logger.debug('Failed to connect. No Host CI will be created')
		if (errObj == None or errObj.errMsg == None or errObj.errMsg.strip() == ''):
			altErr = errorobject.createError(errorcodes.INTERNAL_ERROR ,None , 'Discovery failed due to internal error')
			logger.reportErrorObject(altErr)
		else:
			logger.reportWarningObject(errObj)
	else:
		OSHVResult.addAll(vec)


	return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute("ip_address")
    ip_domain = Framework.getDestinationAttribute("ip_domain")
    cmdb_id = Framework.getDestinationAttribute("cmdb_id")
    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME
    connectionFailedMsgs = []
    protocolIds = findProperProtocolIds(
        ip, netutils.getAvailableProtocols(Framework, protocolName, ip, ip_domain) or []
    )

    if not protocolIds:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        logger.reportErrorObject(errobj)
    else:
        for protocolId in protocolIds:
            protocol = ProtocolManager.getProtocolById(protocolId)
            port = protocol.getProtocolAttribute("protocol_port")

            for version in SUPPORTED_OAM_VERSION:
                props = Properties()
                props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, protocolId)
                props.setProperty("autoAcceptCerts", "true")
                props.setProperty("host", ip)
                try:
                    httpClient = Framework.createClient(props)
                    httpClient.getAsString(
                        "http://%s:%s/oam/services/rest/%s/ssa/policyadmin/appdomain" % (ip, port, version)
                    )

                    oamOsh = modeling.createOshByCmdbId("running_software", cmdb_id)
                    oamOsh.setStringAttribute("credentials_id", protocolId)
                    oamOsh.setStringAttribute("version", version)
                    OSHVResult.add(oamOsh)
                except SocketTimeoutException, e:
                    msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_TIMEOUT)
                    connectionFailedMsgs.append(msg)
                except JException, e:
                    msg = "URL is not accessable: " + e.getMessage()
                    # logger.debugException(msg)
                    connectionFailedMsgs.append(msg)
                finally:
Ejemplo n.º 32
0
def DiscoveryMain(Framework):
    warningsList = []
    errorsList = []
    vector = ObjectStateHolderVector()
    ip_address = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    protocolName = cim.Protocol.DISPLAY

    credentials = netutils.getAvailableProtocols(Framework, cim.Protocol.FULL,
                                                 ip_address, ip_domain)
    credentials = smis_discoverer.getSmisCredentials(credentials, Framework)
    if len(credentials) == 0:
        msg = errormessages.makeErrorMessage(
            protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        warningsList.append(errobj)
        logger.debug(msg)

    smisNamespaces = smis_discoverer.getSmisNamespaces(Framework)
    if not smisNamespaces:
        msg = errormessages.makeErrorMessage(protocolName,
                                             "No SMI-S namespaces found")
        errobj = errorobject.createError(
            errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS,
            [cim.Protocol.DISPLAY, msg], msg)
        errorsList.append(errobj)
        logger.reportErrorObject(errobj)
        return vector

    for credential in credentials:
        testedNamespace = None
        for namespaceObject in smisNamespaces:
            try:

                testedNamespace = cim_discover.testConnectionWithNamespace(
                    Framework, ip_address, credential, namespaceObject)
                break
            except JException, ex:
                msg = ex.getMessage()
                msg = cim_discover.translateErrorMessage(msg)
                errormessages.resolveAndAddToObjectsCollections(
                    msg, protocolName, warningsList, errorsList)
            except:
Ejemplo n.º 33
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    exchangeServerId = Framework.getDestinationAttribute('id')
    fqdn = Framework.getDestinationAttribute('fqdn')
    hostName = getHostName(Framework)

    exchangeServerOsh = ms_exchange_utils.restoreExchangeServerOSH(
        exchangeServerId)

    props = Properties()
    props.put(AgentConstants.PROP_WMI_NAMESPACE, WMI_NAMESPACE)
    try:
        wmiClient = Framework.createClient(props)
        wmiAgent = WmiAgent(wmiClient, Framework)
        try:
            exchangeDiscoverer = ExchangeDiscoverer(wmiAgent,
                                                    exchangeServerOsh,
                                                    Framework, OSHVResult,
                                                    hostName)
            try:
                exchangeDiscoverer.doExchangeSystem(fqdn)
                exchangeDiscoverer.doFolderTrees()
            except:
                errorMsg = 'Failed to discover folder trees and public folders'
                logger.warnException(errorMsg)
                errobj = errorobject.createError(
                    errorcodes.FAILED_DISCOVERING_RESOURCE,
                    ['folder trees and public folders'], errorMsg)
                logger.reportWarningObject(errobj)

            if not exchangeDiscoverer.objectsDiscovered:
                errobj = errorobject.createError(
                    errorcodes.MS_EXCHANGE_OBJECTS_NOT_FOUND, None,
                    'Microsoft Exchange objects not found in discovery')
                logger.reportErrorObject(errobj)
        finally:
            wmiClient.close()
    except:
        exInfo = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(exInfo, WMI_PROTOCOL, Framework)

    return OSHVResult
Ejemplo n.º 34
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        try:
            a10Discoverer = createA10Discoverer(snmpClient, Framework, OSHVResult)
            a10Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NoA10Exception:
        logger.reportWarning("No A10 vThunder found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')

    return OSHVResult
Ejemplo n.º 35
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    (vec, errObj) = NTCMD_Connection_Utils.mainFunction(Framework)

    logger.debug('OSHVector contains ', vec.size(), ' objects.')
    # just in case we couldn't do any connection
    if vec.size() == 0:
        logger.debug('Failed to connect. No Host CI will be created')
        if (errObj == None or errObj.errMsg == None
                or errObj.errMsg.strip() == ''):
            altErr = errorobject.createError(
                errorcodes.INTERNAL_ERROR, None,
                'Discovery failed due to internal error')
            logger.reportErrorObject(altErr)
        else:
            logger.reportWarningObject(errObj)
    else:
        OSHVResult.addAll(vec)

    return OSHVResult
Ejemplo n.º 36
0
 def insertEntitiesProbeDb(self, entitiesbulk):
     st = None
     try:
         try:
             sql = entitiesbulk[0].getInsertSQL()
             st = self.conn.prepareStatement(sql)
             for entity in entitiesbulk:
                 entity.setValues(st)
                 st.addBatch()
             st.executeBatch()
         except:
             error = 'Failed to add entities of type ' + str(
                 entitiesbulk[0].getEntityType()) + ' to Probe database'
             logger.errorException(error)
             errobj = errorobject.createError(
                 errorcodes.FAILED_ADDING_ENTITIES_TO_PROBE_DB,
                 [str(entitiesbulk[0].getEntityType())], error)
             logger.reportErrorObject(errobj)
     finally:
         self.closeStatement(st)
Ejemplo n.º 37
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        try:
            f5Discoverer = createF5Discoverer(snmpClient, Framework, OSHVResult)
            f5Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NoF5Exception:
        logger.reportWarning("No F5 LTM found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')
            
    return OSHVResult
Ejemplo n.º 38
0
def doNextHop(Framework, hostIPs, OSHVResult, shell, runningApplications, processes, connectivityEndPoints, connections,
              hostOsh):
    portToDiscover = Framework.getDestinationAttribute("PORT")
    signatureLoader = asm_signature_loader.SignatureLoader(Framework)
    processMap = buildProcessMap(processes)
    for application in runningApplications:
        results, configFileScp = findConfigFileNextHop(Framework, hostIPs, shell, processMap, application,
                                                       signatureLoader)
        OSHVResult.addAll(results)
        nonTcpScpSet = buildSCPSet(results)

        results, tcpScp, warninglist = findTCPNextHop(Framework, hostIPs, shell, processes, connectivityEndPoints,
                                                      connections, application, hostOsh)
        filterSCP(results, nonTcpScpSet, hostIPs, portToDiscover)
        OSHVResult.addAll(results)

        if int(configFileScp) + int(tcpScp) == 0:
            for warning in warninglist:
                logger.reportErrorObject(warning)

    return OSHVResult
Ejemplo n.º 39
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    try:
        checkAlteon(Framework)
        snmpClient = Framework.createClient()
        ipAddress = Framework.getDestinationAttribute("ip_address")
        hostOsh = modeling.createHostOSH(ipAddress)
        OSHVResult.add(hostOsh)
        try:
            snmpAgent = SnmpAgent(ALTEON_OID_BASE, snmpClient, Framework)
            alteonDiscoverer = AlteonDiscoverer(snmpAgent, OSHVResult, Framework)
            alteonDiscoverer.discoverAlteon(hostOsh)
        finally:
            snmpClient.close()
    except:
        logger.errorException("")
        errobj = errorobject.createError(errorcodes.FAILED_TO_DISCOVER_ALTEON, None, "Failed to discover Alteon")
        logger.reportErrorObject(errobj)

    return OSHVResult
Ejemplo n.º 40
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    
    try:
        checkAlteon(Framework)
        snmpClient = Framework.createClient()
        ipAddress = Framework.getDestinationAttribute('ip_address')
        hostOsh = modeling.createHostOSH(ipAddress)
        OSHVResult.add(hostOsh)
        try:
            snmpAgent = SnmpAgent(ALTEON_OID_BASE, snmpClient, Framework);
            alteonDiscoverer = AlteonDiscoverer(snmpAgent, OSHVResult, Framework)
            alteonDiscoverer.discoverAlteon(hostOsh)
        finally:
            snmpClient.close()
    except:
        logger.errorException('')
        errobj = errorobject.createError(errorcodes.FAILED_TO_DISCOVER_ALTEON, None, 'Failed to discover Alteon')
        logger.reportErrorObject(errobj)
            
    return OSHVResult
Ejemplo n.º 41
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute('ip_address')
    ip_domain = Framework.getDestinationAttribute('ip_domain')
    cmdb_id = Framework.getDestinationAttribute('cmdb_id')
    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME
    connectionFailedMsgs = []
    protocolIds = findProperProtocolIds(ip, netutils.getAvailableProtocols(Framework, protocolName, ip, ip_domain) or [])

    if not protocolIds:
        msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        logger.reportErrorObject(errobj)
    else:
        for protocolId in protocolIds:
            protocol = ProtocolManager.getProtocolById(protocolId)
            port = protocol.getProtocolAttribute('protocol_port')

            for version in SUPPORTED_OAM_VERSION:
                props = Properties()
                props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID, protocolId)
                props.setProperty('autoAcceptCerts', 'true')
                props.setProperty('host', ip)
                try:
                    httpClient = Framework.createClient(props)
                    httpClient.getAsString('http://%s:%s/oam/services/rest/%s/ssa/policyadmin/appdomain' % (ip, port, version))

                    oamOsh = modeling.createOshByCmdbId('running_software', cmdb_id)
                    oamOsh.setStringAttribute('credentials_id', protocolId)
                    oamOsh.setStringAttribute('version', version)
                    OSHVResult.add(oamOsh)
                except SocketTimeoutException, e:
                    msg = errormessages.makeErrorMessage(protocolName, pattern=errormessages.ERROR_TIMEOUT)
                    connectionFailedMsgs.append(msg)
                except JException, e:
                    msg = 'URL is not accessable: ' + e.getMessage()
                    # logger.debugException(msg)
                    connectionFailedMsgs.append(msg)
                finally:
Ejemplo n.º 42
0
def checkNonNativeAgentInstalled(Framework):

    # Set the nonnative flags
    Framework.setProperty(InventoryUtils.STATE_PROPERTY_IS_MIGRATE, 'false')
    InventoryUtils.resetBaseDir(Framework)
    AgentUtils.setUpgradingNativeAgent(Framework, 'true')

    # Ensure we're disconnected
    InventoryUtils.releaseConnection(Framework)

    Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE,
                          AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE)

    # For now - the usual check
    logger.debug(
        'Going to check whether non-native agent already installed or not')

    warningsList = []
    errorsList = []
    agent = AgentUtils.agentConnect(
        Framework,
        AgentUtils.getUdAgentProtocolForMigration(Framework).getIdAsString(),
        warningsList, errorsList)

    if not agent:
        for errobj in warningsList:
            logger.reportWarningObject(errobj)
        for errobj in errorsList:
            logger.reportErrorObject(errobj)

        Framework.reportError(
            inventoryerrorcodes.INVENTORY_DISCOVERY_ENSURE_CONNECTED_FAILED,
            ['Could not connect to the remote agent'])
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    else:
        logger.debug('Connected to agent!!!!')
        Framework.setProperty(AgentUtils.DOWNLOAD_MIGRATE_LOG_FILE, '')
        InventoryUtils.setConnectedClientIdentifier(Framework, agent)
        agent.close()
        Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
Ejemplo n.º 43
0
def DiscoveryMain(Framework):
    resultVector = ObjectStateHolderVector()

    ipAddress = Framework.getDestinationAttribute(DestinationProperty.IP_ADDRESS)
    if not ipAddress:
        msg = errormessages.makeErrorMessage(na.Protocol.DISPLAY, message="Invalid IP address")
        errorObject = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [na.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
        return resultVector
    
    credentialsId = Framework.getParameter(DestinationProperty.CREDENTIALS_ID)
    if not credentialsId:
        msg = errormessages.makeErrorMessage(na.Protocol.DISPLAY, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errorObject = errorobject.createError(errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [na.Protocol.DISPLAY], msg)
        logger.reportErrorObject(errorObject)
        return resultVector

    queryTopologyPerDevice = _getBooleanParameter(JobParameter.QUERY_TOPOLOGY_PER_DEVICE, Framework, False)
    discovererClass = na_discover.SingleRequestsNaDiscoverer
    if queryTopologyPerDevice:
        discovererClass = na_discover.NaDiscovererPerDevice
    
    reportDeviceConfigs = _getBooleanParameter(JobParameter.REPORT_DEVICE_CONFIGS, Framework, False)
    logger.debug('reportDeviceConfigs: ', reportDeviceConfigs)

    reportDeviceModules = _getBooleanParameter(JobParameter.REPORT_DEVICE_MODULES, Framework, False)
    logger.debug('reportDeviceModules:', reportDeviceModules)

    client = None
    try:
        try:
            
            client = na_discover.createJavaClient(Framework, ipAddress, credentialsId)
            
            logger.debug("Topology is discovered by '%s'" % discovererClass.__name__)
            
            discoverer = discovererClass(client, ipAddress, Framework)
            discoverer.setDevicePageSize(500)
            discoverer.setReportDeviceConfigs(reportDeviceConfigs)
            discoverer.setReportDeviceModules(reportDeviceModules)

            discoverResult = discoverer.discover()
            if discoverResult:
                devicesById, connectivitiesByDeviceId = discoverResult

                reporter = na.NaReporter(Framework)
                reporter.setBulkThreshold(10000)
                reporter.setReportDeviceConfigs(reportDeviceConfigs)
                reporter.setReportDeviceModules(reportDeviceModules)

                reporter.report(devicesById, connectivitiesByDeviceId)

        finally:
            client and client.close()
        
    except MissingSdkJarException, ex:
        msg = errormessages.makeErrorMessage(na.Protocol.DISPLAY, message="Not all jar dependencies are found in class path")
        errorObject = errorobject.createError(errorcodes.MISSING_JARS_ERROR, [na.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
Ejemplo n.º 44
0
def DiscoveryMain(Framework):
	OSHVResult = ObjectStateHolderVector()
	try:
		hostId = Framework.getDestinationAttribute('hostId')
		hostOsh = modeling.createOshByCmdbIdString('host_node', hostId);
		
		snmpClient = Framework.createClient()	
		try:	
			cssDiscoverer = createCssDiscoverer(snmpClient, Framework, OSHVResult, hostOsh)
			cssDiscoverer.discoverContentRules()
			cssDiscoverer.discoverServices()
		finally:
			snmpClient.close()
	except NoCssException:
		errobj = errorobject.createError(errorcodes.CSS_NOT_FOUND_ON_TARGET_HOST, None, 'CSS was not found on target host')
		logger.reportErrorObject(errobj)
	except:
		errorMessage = logger.prepareJythonStackTrace('')
		logger.error(errorMessage)
		errormessages.resolveAndReport(errorMessage, 'SNMP', Framework)
					
	return OSHVResult
def DiscoveryMain(Framework):
    resultVector = ObjectStateHolderVector()

    ipAddress = Framework.getDestinationAttribute(
        DestinationProperty.IP_ADDRESS)

    connectionHandler = vmware_cim_discover.DefaultDiscoveryConnectionHandler(
        Framework, discoverConnectedEsx)

    connectionDiscoverer = None
    try:
        connectionDiscoverer = vmware_cim_discover.ConnectionDiscoverer(
            Framework, connectionHandler)
    except (cim_discover.MissingConfigFileException,
            vmware_cim_discover.RuntimeException), ex:
        msg = str(ex)
        errorObject = errorobject.createError(
            errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS,
            [cim.Protocol.DISPLAY, msg], msg)
        logger.reportErrorObject(errorObject)
        logger.error(msg)
        return resultVector
Ejemplo n.º 46
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ipAddress = Framework.getDestinationAttribute('ip_address')
    try:
        snmpClient = Framework.createClient()
        snmpAgent = SnmpAgent(CISCO_ACE_OID_BASE, snmpClient, Framework)
        try:
            cisco_Discoverer = Cisco_Discoverer(snmpAgent, OSHVResult,
                                                Framework)
            cisco_Discoverer.getTopology(ipAddress)
        finally:
            snmpClient.close()
    except NO_CISCO_ACE_Exception:
        logger.reportWarning("No Cisco ACE found on the remote machine")
    except:
        #TODO: use errormessages here
        msg = logger.prepareFullStackTrace('')
        errobj = errormessages.resolveError(msg, 'snmp')
        logger.reportErrorObject(errobj)
        logger.debugException('')

    return OSHVResult
Ejemplo n.º 47
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    ip = Framework.getDestinationAttribute('ip_address')
    domain = Framework.getDestinationAttribute('ip_domain')
    host_id = Framework.getDestinationAttribute('hostId')
    errorsList = []

    protocol = "ldap"
    credential_ids = Framework.getAvailableProtocols(ip, protocol)
    lastConnectedCredential = Framework.loadState()
    lastConnectedCredential and credential_ids.append(lastConnectedCredential)

    if not credential_ids:
        msg = errormessages.makeErrorMessage(
            'webseal', pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, ['webseal'], msg)
        errorsList.append(errobj)

    client = Framework.createClient()
    credential_id = find_valid_credential(credential_ids, client, Framework)

    if credential_id:
        Framework.saveState(credential_id)
        OSHVResult.addAll(reportWebSeal(host_id, credential_id))
    else:
        Framework.clearState()
        msg = errormessages.makeErrorMessage(
            'Shell', pattern=errormessages.ERROR_FAILED_TO_CONNECT_TO_SERVER)
        errobj = errorobject.createError(errorcodes.CONNECTION_FAILED,
                                         ['webseal'], msg)
        errorsList.append(errobj)

    for errobj in errorsList:
        logger.reportErrorObject(errobj)

    return OSHVResult
Ejemplo n.º 48
0
def __discoverInstalledSoftware(Framework, OSHVResult, client):
    discoverSoftwareOld = Boolean.parseBoolean(Framework.getParameter('discoverInstalledSoftwareByOldMechanism'))

    softNameToInstSoftOSH = {}
    try:
        if discoverSoftwareOld:
            #we close client here since in the software discovery we had to open another client
            #since we changing namespace and reference registry instead of wmi
            logger.debug('The software is discovered using old mechanism. This mechanism is very non-efficient and thus discovery might take time.')
            client.close()
            client = None

            wmi_dis_software_lib.mainFunction(Framework, OSHVResult, softNameToInstSoftOSH)

            #reopen general WMI client since it will be used in Plug-ins
            logger.debug("Reopening WMI client")
            client = createWmiClient(Framework)
        else:
            wmi_dis_software_lib.mainFunctionWithWbem(Framework, client, OSHVResult, softNameToInstSoftOSH)
    except:
        errobj = errorobject.createError(errorcodes.FAILED_DISCOVERING_RESOURCE_WITH_CLIENT_TYPE, ['software', 'wmi'], 'Failed to discover software by wmi')
        logger.reportErrorObject(errobj)
        logger.errorException('Failed to discover software by wmi')
    return (softNameToInstSoftOSH, client)
Ejemplo n.º 49
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    ip = Framework.getDestinationAttribute('ip_address')
    credential_id = Framework.getDestinationAttribute('credential_id')
    version = Framework.getDestinationAttribute('version')
    cmdb_id = Framework.getDestinationAttribute('cmdb_id')

    protocol = ProtocolManager.getProtocolById(credential_id)
    host = protocol.getProtocolAttribute('host')
    port = protocol.getProtocolAttribute('protocol_port')

    protocolName = ClientsConsts.HTTP_PROTOCOL_NAME

    if (host and ip != host) or not port:
        msg = errormessages.makeErrorMessage(
            protocolName,
            'Invalid ip address or missing port in HTTP credential',
            pattern=errormessages.ERROR_OPERATION_FAILED)
        errobj = errorobject.createError(errorcodes.OPERATION_FAILED,
                                         [protocolName], msg)
        logger.reportErrorObject(errobj)
    else:
        props = Properties()
        props.setProperty(CollectorsConstants.ATTR_CREDENTIALS_ID,
                          credential_id)
        props.setProperty('autoAcceptCerts', 'true')
        props.setProperty('host', ip)

        try:
            httpClient = Framework.createClient(props)
            builder = PolicyBuilder(ip, port, version, httpClient)
            doc = builder.createPolicyDoc()

            oamServerOSH = modeling.createOshByCmdbIdString(
                'running_software', cmdb_id)
            policyOSH = modeling.createConfigurationDocumentOSH(
                'policy.xml', '', doc, oamServerOSH)
            linkOSH = modeling.createLinkOSH('composition', oamServerOSH,
                                             policyOSH)
            OSHVResult.add(oamServerOSH)
            OSHVResult.add(policyOSH)
            OSHVResult.add(linkOSH)
        except UnauthorizedException, e:
            msg = 'Failed to authenticate: ' + e.getMessage()
            errobj = errorobject.createError(
                errorcodes.INVALID_USERNAME_PASSWORD, [protocolName], msg)
            logger.reportErrorObject(errobj)
        except JException, e:
            msg = 'URL is not accessable: ' + e.getMessage()
            errobj = errorobject.createError(errorcodes.CONNECTION_FAILED,
                                             [protocolName], msg)
            logger.reportErrorObject(errobj)
Ejemplo n.º 50
0
def checkAgentInstalled(Framework, ignoreError=False):
    # Ensure we're disconnected
    InventoryUtils.releaseConnection(Framework)

    Framework.setProperty(AgentUtils.DOWNLOAD_INSTALL_LOG_FILE, AgentUtils.DOWNLOAD_INSTALL_LOG_FILE)

    if Framework.getProperty(FIRST_TRY_INSTALL_AGENT) is None:
        # we don't want immediately check whether agent installed or not, since for sure it is not. go to parking
        # to let others to install
        logger.debug('UD agent install command just run, will check after parking')
        Framework.setProperty(FIRST_TRY_INSTALL_AGENT, FIRST_TRY_INSTALL_AGENT)
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
        return
    else:
        logger.debug('Going to check whether agent already installed or not')

    # errorCode = AgentUtils.getInstallErrorCode(Framework)
    # if not errorCode.isSuccess():
    #     logger.debug('Failed to install agent.')
    #     Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_FAILED_AGENT_INSTALL, None)
    #     Framework.setStepExecutionStatus(WorkflowStepStatus.FATAL_FAILURE)
    #     return

    warningsList = []
    errorsList = []

    # When we migrate ddmi to uda, we already know what cred_id to use
    ddmiMigrationCredId = AgentUtils.getUdAgentProtocolForMigration(Framework)
    if ddmiMigrationCredId:
        conToUse = ddmiMigrationCredId.getIdAsString()
    else:
        conToUse = None

    agent = AgentUtils.agentConnect(Framework, conToUse, warningsList, errorsList)
    if not agent:
        if not ignoreError:
            for errobj in warningsList:
                logger.reportWarningObject(errobj)
            for errobj in errorsList:
                logger.reportErrorObject(errobj)
            Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_ENSURE_CONNECTED_FAILED, ['Could not connect to the remote agent'])
        Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
    else:
        try:
            logger.debug('Connected to agent!!!!')

            # Check whether the agent is native
            agentsConfigFile = Framework.getConfigFile(CollectorsConstants.AGENTSSBYPLATFORM_FILE_NAME)

            platform = Framework.getProperty(InventoryUtils.STATE_PROPERTY_PLATFORM)
            architecture = Framework.getProperty(InventoryUtils.STATE_PROPERTY_ARCHITECTURE)

            agentPlatformConfig = agentsConfigFile.getPlatformConfiguration(platform, architecture)
            isNativeCmd = agentPlatformConfig.getIsNativeCmd()
            logger.debug('Native command is [' + str(isNativeCmd) + ']')

            if isNativeCmd and len(isNativeCmd) > 0:
                isNativeCmd = InventoryUtils.handleBaseDirPath(Framework, isNativeCmd)
                isNative = agent.executeCmd(isNativeCmd)
                if isNative != 'true':
                    logger.debug('Could not verify whether the remote agent is native')
                    Framework.reportError(inventoryerrorcodes.INVENTORY_DISCOVERY_ENSURE_CONNECTED_FAILED,
                        ['Remote agent doesnt appear to be natively installed'])
                    Framework.setStepExecutionStatus(WorkflowStepStatus.FAILURE)
                    return

            # Reporting agent osh to framework
            Framework.setProperty(AgentUtils.DOWNLOAD_INSTALL_LOG_FILE, '')
            Framework.setProperty(InventoryUtils.STATE_PROPERTY_AGENT_INSTALLED, InventoryUtils.STATE_PROPERTY_AGENT_INSTALLED)
            AgentUtils.saveGlobalState(agent, Framework)

            OSHVResult = ObjectStateHolderVector()
            ip = Framework.getProperty(InventoryUtils.STATE_PROPERTY_CONNECTED_SHELL_IP)
            hostOsh = modeling.createHostOSH(ip)
            uduid = InventoryUtils.getUduid(agent)
            hostOsh.setStringAttribute(InventoryUtils.ATTR_UD_UNIQUE_ID, uduid)

            agentOsh = AgentUtils.createAgentOsh(agent, Framework)
            agentOsh.setContainer(hostOsh)
            OSHVResult.add(hostOsh)
            OSHVResult.add(agentOsh)
            Framework.sendObjects(OSHVResult)
            Framework.flushObjects()
            Framework.setStepExecutionStatus(WorkflowStepStatus.SUCCESS)
        finally:
            if agent:
                agent.close()
Ejemplo n.º 51
0
def DiscoveryMain(Framework):

    OSHVResult = ObjectStateHolderVector()
    ms_domain_name = Framework.getDestinationAttribute('ms_domain_name')
    if not ms_domain_name:
        ms_domain_name = 'NULL'

    try:
        netUtil = MsNetworkUtil()
        hostsOutput = netUtil.doNetServerEnum('NULL', SV_TYPE_SERVER,
                                              ms_domain_name)
        if hostsOutput != None:
            discoverUnknownIPs = 1
            try:
                strDiscoverUnknownIPs = Framework.getParameter(
                    'discoverUnknownIPs')
                discoverUnknownIPs = Boolean.parseBoolean(
                    strDiscoverUnknownIPs)
            except:
                pass

            oshMsDomain = ObjectStateHolder('msdomain')
            oshMsDomain.setStringAttribute('data_name', ms_domain_name)
            alreadyDiscoveredIps = HashMap()
            for hostInfo in hostsOutput:
                hostType = Long(hostInfo[1]).longValue()
                hostName = (str(hostInfo[0])).lower()
                try:
                    ip = InetAddress.getByName(hostInfo[0]).getHostAddress()
                    if netutils.isLocalIp(ip):
                        continue
                    cachedHostName = alreadyDiscoveredIps.get(ip)
                    if cachedHostName != None:
                        logger.debug(
                            'IP ', ip,
                            ' already reported for host ' + cachedHostName,
                            ' current host ', hostName, ' - skipping')
                        continue
                    else:
                        logger.debug('Discovered IP ' + ip + ' for host ' +
                                     hostName)
                        alreadyDiscoveredIps.put(ip, hostName)
                    ipDomain = DomainScopeManager.getDomainByIp(ip)
                    if not discoverUnknownIPs and ipDomain == 'unknown':
                        logger.debug(
                            'ip: ' + ip +
                            ' is out of probe range and will be excluded')
                        continue
                    if SV_TYPE_CLUSTER_NT & hostType:
                        logger.debug(
                            'Not reporting the entry %s because it is a Cluster'
                            % hostName)
                        continue
                    hostOsType = 'nt'
                    if SV_TYPE_SERVER_UNIX & hostType:
                        hostOsType = 'unix'
                    oshHost = modeling.createHostOSH(ip, hostOsType)
                    oshHost.setStringAttribute("host_hostname", hostName)
                    OSHVResult.add(oshHost)

                    link = modeling.createLinkOSH('member', oshMsDomain,
                                                  oshHost)
                    OSHVResult.add(link)
                    ipOSH = modeling.createIpOSH(ip)
                    OSHVResult.add(ipOSH)
                    contained = modeling.createLinkOSH('contained', oshHost,
                                                       ipOSH)
                    OSHVResult.add(contained)
                except:
                    errorMsg = str(sys.exc_info()[1]).strip()
                    logger.warn('Failed to resolve host ', hostInfo[0], ' : ',
                                errorMsg)
        else:
            message = 'Failed to discover hosts on MS Domain'
            logger.warn(message)
            logger.reportWarning(message)
    except:
        errorMsg = str(sys.exc_info()[1]).strip()
        logger.errorException('Failed to discovery MS Domains')
        errorMessage = errormessages.makeErrorMessage(
            "msdomain", errorMsg,
            errormessages.ERROR_FAILED_DISCOVERING_MSDOMAIN_HOSTS)
        errobj = errorobject.createError(
            errorcodes.FAILED_DISCOVERIING_MSDOMAIN_HOST,
            ["msdomain", errorMsg], errorMessage)
        logger.reportErrorObject(errobj)
    return OSHVResult
Ejemplo n.º 52
0
    def discover_private(self):
        ports = self.servicesPorts(0)
        query = 'select ipaddress, port, Protocol from Port_Process '
        if (ports != None) and (len(ports) > 0):
            query = query + ' where listen and port IN (' + ports + ')'
        logger.debug('ListenPorts,sql:', query)
        conn = self.Framework.getProbeDatabaseConnection('TCPDISCOVERY')
        st = None
        result = None
        try:
            try:
                if logger.isDebugEnabled():
                    logger.debug(query)
                st = conn.createStatement()
                result = st.executeQuery(query)
                dataFound = 0
                while result.next():
                    dataFound = 1
                    address = result.getString('ipaddress');
                    port = result.getInt('port');
                    prot = result.getInt('Protocol');
                    if not self.shouldInclude(address, 1):
                        if logger.isDebugEnabled():
                            logger.debug("ignoring ip out of scope: " + address)
                        continue
                    ipOSH = modeling.createIpOSH(address)
                    self.Framework.sendObject(ipOSH)

                    hostOSH = modeling.createHostOSH(address)
                    portName = self.knownPortsConfigFile.getPortName(prot, port)
                    if portName == None:
                        portName = str(port)

                    portType = modeling.SERVICEADDRESS_TYPE_TCP
                    if prot == modeling.UDP_PROTOCOL:
                        portType = modeling.SERVICEADDRESS_TYPE_UDP

                    serverPortOSH = modeling.createServiceAddressOsh(hostOSH, address, port, portType, portName)
                    containedLinkOSH = modeling.createLinkOSH('contained', hostOSH, ipOSH)
                    self.Framework.sendObject(hostOSH)
                    self.Framework.sendObject(serverPortOSH)
                    self.Framework.sendObject(containedLinkOSH)
                if not dataFound:
                    self.Framework.reportWarning("No data to process, please check if Host Resources jobs had already run")
            except:
                msg = sys.exc_info()[1]
                exInfo = '%s' % msg
                if exInfo.find('ResultSet closed') != -1:
                    error = 'Connection to probe database closed'
                    details = str("Please increase job execution max time and/or configure parameter 'appilog.agent.netflow.heldTimeoutConnection' in DiscoveryProbe.properties file")
                    errobj = errorobject.createError(errorcodes.INTERNAL_ERROR_WITH_PROTOCOL_DETAILS, [error, details], error + details)
                    logger.reportErrorObject(errobj)
                else:
                    errobj = errorobject.createError(errorcodes.FAILED_TO_EXECUTE_SQL, [exInfo], exInfo)
                    logger.reportErrorObject(errobj)
        finally:
            if result != None:
                try:
                    result.close
                except:
                    pass
            conn.close(st)
            conn.close()
Ejemplo n.º 53
0
                errormessages.resolveAndAddToObjectsCollections(
                    trace, protocolName, warningsList, errorsList)

        if testedNamespace is not None:
            hostOsh = modeling.createHostOSH(ip_address)
            smisOsh = cim.createCimOsh(ip_address, hostOsh, credential,
                                       smis.CimCategory.SMIS)
            smisOsh.setStringAttribute('application_category', 'Storage')
            vector.add(hostOsh)
            vector.add(smisOsh)
            warningsList = []
            errorsList = []
            break

    if vector.size() <= 0:
        Framework.clearState()
        if (len(warningsList) == 0) and (len(errorsList) == 0):
            msg = errormessages.makeErrorMessage(
                protocolName, pattern=errormessages.ERROR_GENERIC)
            logger.debug(msg)
            errobj = errorobject.createError(
                errorcodes.INTERNAL_ERROR_WITH_PROTOCOL, [protocolName], msg)
            errorsList.append(errobj)
    if errorsList:
        for errorObj in errorsList:
            logger.reportErrorObject(errorObj)
    if warningsList:
        for warnObj in warningsList:
            logger.reportErrorObject(warnObj)
    return vector
Ejemplo n.º 54
0
                                    logger.debugException(str(e))
                                    warning = errorobject.createError(
                                        errorcodes.INTERNAL_ERROR, None,
                                        "%s failed" % discovery.description)
                                    discoveryWarnings.append(warning)
    # === Error cases handling ===

    # Discovery finished and we have to show reasons in the UI:
    #
    # * No credentials found for _aws_ protocol
    if not credentials:
        msg = errormessages.makeErrorMessage(
            protocolName, pattern=errormessages.ERROR_NO_CREDENTIALS)
        errobj = errorobject.createError(
            errorcodes.NO_CREDENTIALS_FOR_TRIGGERED_IP, [protocolName], msg)
        logger.reportErrorObject(errobj)
    # * Among enabled flows no successful discovery
    elif not oneDiscoveryHappened:
        errobj = errorobject.createError(errorcodes.FAILED_RUNNING_DISCOVERY,
                                         ['Amazon Cloud'],
                                         'Failed to make discovery')
        logger.reportErrorObject(errobj)

    # * Other, like connection troubles or failed discovery
    map(logger.reportErrorObject, discoveryErrors)
    map(logger.reportWarningObject, discoveryWarnings)
    return ObjectStateHolderVector()


# Discovery details
# -----------------
Ejemplo n.º 55
0
def reportErrors(warningsList, errorsList):
    for errobj in warningsList:
        logger.reportWarningObject(errobj)
    for errobj in errorsList:
        logger.reportErrorObject(errobj)
    return