Search in sources :

Example 6 with IPPollRange

use of org.opennms.netmgt.model.discovery.IPPollRange in project opennms by OpenNMS.

the class DiscoveryConfigFactory method getRanges.

/**
     * <p>getRanges</p>
     *
     * @return a {@link java.util.List} object.
     */
@Override
public List<IPPollRange> getRanges() {
    final List<IPPollRange> includes = new LinkedList<IPPollRange>();
    getReadLock().lock();
    try {
        Long defaultTimeout = getConfiguration().getTimeout().orElse(DEFAULT_TIMEOUT);
        Integer defaultRetries = getConfiguration().getRetries().orElse(DEFAULT_RETRIES);
        for (final IncludeRange ir : getConfiguration().getIncludeRanges()) {
            // Validate IP range; if invalid, then log and discard this range
            try {
                InetAddressUtils.toIpAddrBytes(ir.getBegin());
            } catch (Throwable e) {
                LOG.warn("Begin address of discovery range is invalid, discarding: {}", ir.getBegin());
                continue;
            }
            try {
                InetAddressUtils.toIpAddrBytes(ir.getEnd());
            } catch (Throwable e) {
                LOG.warn("End address of discovery range is invalid, discarding: {}", ir.getEnd());
                continue;
            }
            long timeout = ir.getTimeout().orElse(defaultTimeout);
            int retries = ir.getRetries().orElse(defaultRetries);
            try {
                includes.add(new IPPollRange(ir.getForeignSource().orElse(null), ir.getLocation().orElse(null), ir.getBegin(), ir.getEnd(), timeout, retries));
            } catch (final UnknownHostException uhE) {
                LOG.warn("Failed to convert address range ({}, {})", ir.getBegin(), ir.getEnd(), uhE);
            }
        }
        return includes;
    } finally {
        getReadLock().unlock();
    }
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) UnknownHostException(java.net.UnknownHostException) IPPollRange(org.opennms.netmgt.model.discovery.IPPollRange) LinkedList(java.util.LinkedList)

Aggregations

IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)6 List (java.util.List)3 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Collectors (java.util.stream.Collectors)2 StreamSupport (java.util.stream.StreamSupport)2 IPAddress (org.opennms.core.network.IPAddress)2 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)2 IPPollAddress (org.opennms.netmgt.model.discovery.IPPollAddress)2 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 BigInteger (java.math.BigInteger)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1