Beispiel #1
0
def createOAMDependenyScp(shell, apacheOsh, apacheScpOsh, uri, default_address, resultsVector):
    """
    Create scp under apache for the given uri.
    Create c-p link from webgate scp to the new scp
    """
    logger.debug('add oam uri to result vector: ', uri)

    uri_pattern = re.compile(r"^(?P<protocol>http|https)://(?P<ip>[\w\.\-]+)(:(?P<port>\d+))?(?P<root>/.*?)?$")
    match = uri_pattern.match(uri)
    if not match:
        if uri[0] != '/':
            uri = '/%s' % uri
        uri = 'http://%s%s' % (default_address, uri)
        logger.debug('use absolute uri: ', uri)
        match = uri_pattern.match(uri)
    if match:
        protocol = match.group('protocol') or 'http'
        ip = match.group('ip')
        port = match.group('port') or '80'
        root = match.group('root') or '/'
        if ip:
            scpOshs = scp.createScpOSHV(apacheOsh, protocol, ip, port, root, shell)
            if scpOshs.size():
                scpOsh = scpOshs.get(0)
                cpLinkOsh = modeling.createLinkOSH('consumer_provider', apacheScpOsh, scpOsh)
                resultsVector.add(scpOsh)
                resultsVector.add(cpLinkOsh)
                return resultsVector

    logger.debug('Skip invalid uri %s' % uri)
    return resultsVector
def process(Framework, configSignature, application, shell, processMap, hostIPs):
    OSHVResult = ObjectStateHolderVector()
    variableResolver = VariableResolver()
    fileProcessUtil = FileProcessUtil(shell, variableResolver)
    cmdlines = getattr(application, TAG_COMMAND_LINE, None)
    includeParentProcesses = False
    if cmdlines:
        if isinstance(cmdlines, list):
            for cmdline in cmdlines:
                if cmdline.includeParentProcesses:
                    includeParentProcesses = True
                    break
        else:
            includeParentProcesses = cmdlines.includeParentProcesses
    createPredefinedVariables(Framework, processMap if includeParentProcesses else None, application, variableResolver)
    for signature in configSignature.children:
        if signature.getType() == TAG_COMMAND_LINE:
            processCommandLine(signature, application, shell, processMap, variableResolver)
        elif signature.getType().endswith(TAG_FILE):
            collectedConfigFiles = fileProcessUtil.process(signature)
            for configFile in collectedConfigFiles:
                configFile.setContainer(application.getOsh())
                OSHVResult.add(configFile.getOsh())
        elif signature.getType() == TAG_OUTPUT:
            scps = processOutput(signature, variableResolver)
            if scps:
                for scpData in scps:
                    scpData['container'] = application.getOsh()
                    scpData['shell'] = shell
                    scpData['localIP'] = hostIPs
                    scpData['dnsServers'] = Framework.getParameter('dnsServers')
                    scpOSHV = scp.createScpOSHV(**scpData)
                    OSHVResult.addAll(scpOSHV)

    return OSHVResult
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    businessElementId = Framework.getDestinationAttribute('id')
    urlString = Framework.getDestinationAttribute('url')
    jobId = Framework.getDiscoveryJobId()
    dnsServers = Framework.getParameter('dnsServers') or None
    shell = None

    if dnsServers:
        dnsServers = [
            dnsServer for dnsServer in dnsServers.split(',')
            if dnsServer and dnsServer.strip()
        ] or None
    if dnsServers:
        logger.debug('Using dns servers: ', dnsServers)

    if not urlString:
        msg = "There is no specified URL in the input BusinessElement CI"
        errormessages.resolveAndReport(msg, jobId, Framework)
        return OSHVResult

    try:
        bizOSH = modeling.createOshByCmdbIdString('business_element',
                                                  businessElementId)
        OSHVResult.add(bizOSH)
        urlString = urlString[1:len(urlString) - 1]

        if netutils.isValidIp(urlString):
            productName = Framework.getDestinationAttribute('product')
            OSHVResult.add(
                scp.createScpOsh(bizOSH, 'tcp', urlString, 0, productName))
        else:
            protocol, hostname, port, context = parseUrl(urlString)
            if not hostname:
                raise ValueError("Hostname is not defined in URL '%s'" %
                                 urlString)

            if not protocol:
                raise ValueError(
                    "Failed to resolve the protocol from specified URL")

            shell = shellutils.ShellUtils(
                Framework.createClient(
                    ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))
            OSHVResult.addAll(
                scp.createScpOSHV(bizOSH,
                                  protocol,
                                  hostname,
                                  port,
                                  context,
                                  shell,
                                  dnsServers=dnsServers))

    except ValueError, e:
        errormessages.resolveAndReport(e.message, jobId, Framework)
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()
    businessElementId = Framework.getDestinationAttribute('id')
    urlString = Framework.getDestinationAttribute('url')
    jobId = Framework.getDiscoveryJobId()
    dnsServers = Framework.getParameter('dnsServers') or None
    shell = None

    if dnsServers:
        dnsServers = [dnsServer for dnsServer in dnsServers.split(',') if dnsServer and dnsServer.strip()] or None
    if dnsServers:
        logger.debug('Using dns servers: ', dnsServers)

    if not urlString:
        msg = "There is no specified URL in the input BusinessElement CI"
        errormessages.resolveAndReport(msg, jobId, Framework)
        return OSHVResult

    try:
        bizOSH = modeling.createOshByCmdbIdString('business_element', businessElementId)
        OSHVResult.add(bizOSH)
        urlString = urlString[1:len(urlString) - 1]

        if netutils.isValidIp(urlString):
            productName = Framework.getDestinationAttribute('product')
            OSHVResult.add(scp.createScpOsh(bizOSH, 'tcp', urlString, 0, productName))
        else:
            protocol, hostname, port, context = parseUrl(urlString)
            if not hostname:
                raise ValueError("Hostname is not defined in URL '%s'" % urlString)

            if not protocol:
                raise ValueError("Failed to resolve the protocol from specified URL")

            shell = shellutils.ShellUtils(Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME))
            OSHVResult.addAll(scp.createScpOSHV(bizOSH, protocol, hostname, port, context, shell, dnsServers=dnsServers))

    except ValueError, e:
        errormessages.resolveAndReport(e.message, jobId, Framework)
Beispiel #5
0
def reportProcessToPort(processes, endpoints, applicationOsh, shell, localip):
    OSHVResult = ObjectStateHolderVector()
    if endpoints:
        key_to_endpoints_map = {}
        [key_to_endpoints_map.update({x.getKey(): x.getEndpoints()}) for x in endpoints]

        for process in processes:
            remotes = key_to_endpoints_map.get(process.getPid())
            if remotes:
                for remote in remotes:
                    address = remote.getAddress()
                    if not isinstance(address, (ip_addr.IPv4Address, ip_addr.IPv6Address)):
                        address = ip_addr.IPAddress(address)
                    port = remote.getPort()
                    if isinstance(address, ip_addr.IPv6Address):
                        logger.debug("ignore ipv6 address:", address)
                        continue
                    logger.debug("reporting remote address:", address)
                    logger.debug("reporting remote port:", port)
                    scpOshv = scp.createScpOSHV(applicationOsh, scp.TCP_TYPE, str(address), port, None, shell, localip)
                    OSHVResult.addAll(scpOshv)

    return OSHVResult