Example #1
0
def DiscoveryMain(Framework):
    properties = Properties()

    properties.setProperty('timeoutDiscover', Framework.getParameter('timeoutDiscover'))
    properties.setProperty('retryDiscover', Framework.getParameter('retryDiscover'))
    properties.setProperty('pingProtocol', Framework.getParameter('pingProtocol'))
    properties.setProperty('threadPoolSize', Framework.getParameter('threadPoolSize'))

    excludePatterns = icmp_utils.preparePatterns(Framework.getParameter('excludePatternsList'))
    
    virtualMode = Framework.getParameter('virtualModeDiscover').lower() == "true"
    rangeString = Framework.getParameter('range') or 'NA'
    probeName = Framework.getDestinationAttribute('probeName')
    ignoreClientType = getGlobalSetting().getPropertyStringValue('pingClientTypeIp', "False").lower() == "false"
    maxAllowedIPv6CountPerRange = long(getGlobalSetting().getPropertyStringValue('maxPingIPv6CountPerRange', str(DEFAULT_MAX_PING_IPV6_COUNT_PER_RANGE)))

    logger.debug("Max allowed IPv6 range size:", maxAllowedIPv6CountPerRange)
    isPingIPv4, isPingIPv6 = getIPSupport(Framework)

    try:
        client = Framework.createClient(ClientsConsts.ICMP_PROTOCOL_NAME, properties)
        try:
            totalReportedIps = 0
            selectedRangeList = _convertToRanges(rangeString)
            probeRanges = icmp_utils.getProbeRanges(selectedRangeList, probeName, Framework, isPingIPv4, isPingIPv6)

            logger.info('Start working on total probe ranges: ', len(probeRanges))
            logger.info('ignoreClientType = ', ignoreClientType)
            #probeRanges = getDataCenterIPRanges(probeRanges)
            for probeRange in probeRanges:
                rangeSize = long(probeRange.getRangeSize())
                if rangeSize > maxAllowedIPv6CountPerRange:
                    logger.reportWarning(
                        "The size of IPv6 range (%s) is %d, exceeds the max range size %d, will skip it." % (
                            probeRange.toRangeString(), rangeSize, maxAllowedIPv6CountPerRange))
                    continue
                totalReportedIps += icmp_utils.pingIPsInRange(Framework, client, probeRange, virtualMode,
                                                              excludePatterns=excludePatterns,ignoreClientType=ignoreClientType)
                Framework.saveState(probeRange.toRangeString())
            logger.debug('Total reported IPs %s ' % totalReportedIps)
            logger.info('Finished working on all Probes Ranges..')

            Framework.clearState()
            if not totalReportedIps:
                logger.reportWarning("No live IPs found in probe ranges")
        finally:
            client.close()
    except:
        msg = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(msg, ClientsConsts.ICMP_PROTOCOL_NAME, Framework)
    return ObjectStateHolderVector()
Example #2
0
def DiscoveryMain(Framework):

    rangeString = Framework.getParameter('range')
    probeName = Framework.getDestinationAttribute('probeName')
    nmapLocation = Framework.getParameter('nmap_location') or None

    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        excludePatterns = icmp_utils.preparePatterns(Framework.getParameter('excludePatternsList'))
        client = Framework.createClient(ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = ShellFactory().createShell(client)
        fs = file_system.createFileSystem(shell)
        try:
            if nmapLocation and fs.isDirectory(nmapLocation):
                path_tool = NtPath()
                nmapLocation = path_tool.join(nmapLocation, nmap.NMAP_EXECUTABLES[1])
        except PathNotFoundException:
            logger.warn("Specified directory \"%s\" is not exists." % nmapLocation)

        if nmapLocation and not nmap.NmapPathValidator.get(fs).validate(nmapLocation):
            logger.warn("Specified Nmap path \"%s\" is not exists. Trying the system path..." % nmapLocation)
            nmapLocation = None

        nmapTool = nmap.getByShell(shell, nmapLocation)
        if not nmapTool.getVersion():
            logger.reportWarning("NMAP command is not installed on the probe machine")
            return ObjectStateHolderVector()
        probeRanges = _buildProbeRanges(Framework, rangeString, probeName)

        logger.info('Start working on total probe ranges: ', len(probeRanges))

        for probeRange in probeRanges:

            logger.debug("Start working on range ", probeRange.toRangeString())
            rangeIps = probeRange.getAllIPs(probeRange.getTotalIPs())
            byExcludePatterns = lambda ip, patterns = excludePatterns: icmp_utils.shouldPingIp(ip, patterns, None)
            filteredIps = filter(byExcludePatterns, rangeIps)

            excludedIpCount = len(rangeIps) - len(filteredIps)
            if excludedIpCount:
                logger.debug("Excluded IP's count: %s " % excludedIpCount)

            try:
                liveIps = nmapTool.doPingScan(filteredIps, issubclass(probeRange.__class__, IPv6Range) or issubclass(probeRange.__class__, IPv6RangeWIthDescription))
            except Exception, ex:
                logger.warn(str(ex))
            else:
                if liveIps:
                    Framework.sendObjects(_reportIpOSHs(liveIps))
        logger.info('Finished working on all Probes Ranges')
Example #3
0
def DiscoveryMain(Framework):
    properties = Properties()

    properties.setProperty('timeoutDiscover', Framework.getParameter('timeoutDiscover'))
    properties.setProperty('retryDiscover', Framework.getParameter('retryDiscover'))
    properties.setProperty('pingProtocol', Framework.getParameter('pingProtocol'))
    properties.setProperty('threadPoolSize', Framework.getParameter('threadPoolSize'))

    excludePatterns = icmp_utils.preparePatterns(Framework.getParameter('excludePatternsList'))
    rangeString = Framework.getParameter('range') or 'NA'
    probeName = Framework.getDestinationAttribute('probeName')
    selectedRangeList = None

    #clear it because IP seep will load state for 'IP range'. See 'icmp_utils.getProbeRanges()'
    Framework.clearState()
    
    try:
        client = Framework.createClient(ClientsConsts.ICMP_PROTOCOL_NAME, properties)
        try:
            if rangeString != 'NA':
                selectedRangeList = SNMP_Connection_Utils.splitByRanges(rangeString)
            probeRangesForIPv6 = icmp_utils.getProbeRanges(selectedRangeList, probeName, Framework, False, True)
            if SNMP_Connection_Utils.isIPv6Overflow(probeRangesForIPv6): # if IPv6 addresses exceeds the max allowed count, won't ping
                return []
            probeRanges = icmp_utils.getProbeRanges(selectedRangeList, probeName, Framework, True, True)

            logger.debug('Start working on total probe ranges: ', len(probeRanges))
            for probeRange in probeRanges:
                if (probeRange.getType().equals(RangeType.CLIENT)
                    or probeRange.getType().equals('Client')):
                    SNMP_Connection_Utils.discoverClientInRange(Framework, client, probeRange, excludePatterns)
            logger.debug('Finished working on all Probes Ranges.')
        finally:
            client.close()
    except:
        msg = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(msg, ClientsConsts.ICMP_PROTOCOL_NAME, Framework)

    return ObjectStateHolderVector()
Example #4
0
def DiscoveryMain(Framework):

    rangeString = Framework.getParameter('range')
    probeName = Framework.getDestinationAttribute('probeName')
    nmapLocation = Framework.getParameter('nmap_location') or None

    protocol = Framework.getDestinationAttribute('Protocol')
    try:
        excludePatterns = icmp_utils.preparePatterns(
            Framework.getParameter('excludePatternsList'))
        client = Framework.createClient(
            ClientsConsts.LOCAL_SHELL_PROTOCOL_NAME)
        shell = ShellFactory().createShell(client)
        fs = file_system.createFileSystem(shell)
        try:
            if nmapLocation and fs.isDirectory(nmapLocation):
                path_tool = NtPath()
                nmapLocation = path_tool.join(nmapLocation,
                                              nmap.NMAP_EXECUTABLES[1])
        except PathNotFoundException:
            logger.warn("Specified directory \"%s\" is not exists." %
                        nmapLocation)

        if nmapLocation and not nmap.NmapPathValidator.get(fs).validate(
                nmapLocation):
            logger.warn(
                "Specified Nmap path \"%s\" is not exists. Trying the system path..."
                % nmapLocation)
            nmapLocation = None

        nmapTool = nmap.getByShell(shell, nmapLocation)
        if not nmapTool.getVersion():
            logger.reportWarning(
                "NMAP command is not installed on the probe machine")
            return ObjectStateHolderVector()
        probeRanges = _buildProbeRanges(Framework, rangeString, probeName)

        logger.info('Start working on total probe ranges: ', len(probeRanges))

        for probeRange in probeRanges:

            logger.debug("Start working on range ", probeRange.toRangeString())
            rangeIps = probeRange.getAllIPs(probeRange.getTotalIPs())
            byExcludePatterns = lambda ip, patterns=excludePatterns: icmp_utils.shouldPingIp(
                ip, patterns, None)
            filteredIps = filter(byExcludePatterns, rangeIps)

            excludedIpCount = len(rangeIps) - len(filteredIps)
            if excludedIpCount:
                logger.debug("Excluded IP's count: %s " % excludedIpCount)

            try:
                liveIps = nmapTool.doPingScan(
                    filteredIps,
                    issubclass(probeRange.__class__, IPv6Range) or issubclass(
                        probeRange.__class__, IPv6RangeWIthDescription))
            except Exception, ex:
                logger.warn(str(ex))
            else:
                if liveIps:
                    Framework.sendObjects(_reportIpOSHs(liveIps))
        logger.info('Finished working on all Probes Ranges')
Example #5
0
def DiscoveryMain(Framework):
    properties = Properties()

    properties.setProperty('timeoutDiscover',
                           Framework.getParameter('timeoutDiscover'))
    properties.setProperty('retryDiscover',
                           Framework.getParameter('retryDiscover'))
    properties.setProperty('pingProtocol',
                           Framework.getParameter('pingProtocol'))
    properties.setProperty('threadPoolSize',
                           Framework.getParameter('threadPoolSize'))

    excludePatterns = icmp_utils.preparePatterns(
        Framework.getParameter('excludePatternsList'))

    virtualMode = Framework.getParameter(
        'virtualModeDiscover').lower() == "true"
    rangeString = Framework.getParameter('range') or 'NA'
    probeName = Framework.getDestinationAttribute('probeName')
    ignoreClientType = getGlobalSetting().getPropertyStringValue(
        'pingClientTypeIp', "False").lower() == "false"
    maxAllowedIPv6CountPerRange = long(
        getGlobalSetting().getPropertyStringValue(
            'maxPingIPv6CountPerRange',
            str(DEFAULT_MAX_PING_IPV6_COUNT_PER_RANGE)))

    logger.debug("Max allowed IPv6 range size:", maxAllowedIPv6CountPerRange)
    isPingIPv4, isPingIPv6 = getIPSupport(Framework)

    try:
        client = Framework.createClient(ClientsConsts.ICMP_PROTOCOL_NAME,
                                        properties)
        try:
            totalReportedIps = 0
            selectedRangeList = _convertToRanges(rangeString)
            probeRanges = icmp_utils.getProbeRanges(selectedRangeList,
                                                    probeName, Framework,
                                                    isPingIPv4, isPingIPv6)

            logger.info('Start working on total probe ranges: ',
                        len(probeRanges))
            logger.info('ignoreClientType = ', ignoreClientType)
            #probeRanges = getDataCenterIPRanges(probeRanges)
            for probeRange in probeRanges:
                rangeSize = long(probeRange.getRangeSize())
                if rangeSize > maxAllowedIPv6CountPerRange:
                    logger.reportWarning(
                        "The size of IPv6 range (%s) is %d, exceeds the max range size %d, will skip it."
                        % (probeRange.toRangeString(), rangeSize,
                           maxAllowedIPv6CountPerRange))
                    continue
                totalReportedIps += icmp_utils.pingIPsInRange(
                    Framework,
                    client,
                    probeRange,
                    virtualMode,
                    excludePatterns=excludePatterns,
                    ignoreClientType=ignoreClientType)
                Framework.saveState(probeRange.toRangeString())
            logger.debug('Total reported IPs %s ' % totalReportedIps)
            logger.info('Finished working on all Probes Ranges..')

            Framework.clearState()
            if not totalReportedIps:
                logger.reportWarning("No live IPs found in probe ranges")
        finally:
            client.close()
    except:
        msg = logger.prepareJythonStackTrace('')
        errormessages.resolveAndReport(msg, ClientsConsts.ICMP_PROTOCOL_NAME,
                                       Framework)
    return ObjectStateHolderVector()