Search in sources :

Example 11 with Specific

use of org.opennms.netmgt.config.discovery.Specific in project opennms by OpenNMS.

the class RangeChunkerTest method testConsecutiveSpecificsWithDifferentTimeouts.

@Test
public void testConsecutiveSpecificsWithDifferentTimeouts() {
    DiscoveryConfiguration config = new DiscoveryConfiguration();
    for (long i = 0; i < 5; i++) {
        Specific specific = new Specific();
        specific.setAddress("10.0.0." + i);
        specific.setForeignSource("ABC");
        specific.setLocation("123");
        specific.setRetries(5);
        specific.setTimeout(i + 1);
        config.addSpecific(specific);
    }
    Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
    printJobs(jobs);
    assertEquals(1, jobs.get("123").size());
    assertEquals(5, jobs.get("123").get(0).getRanges().size());
}
Also used : DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) List(java.util.List) Specific(org.opennms.netmgt.config.discovery.Specific) Test(org.junit.Test)

Example 12 with Specific

use of org.opennms.netmgt.config.discovery.Specific in project opennms by OpenNMS.

the class DiscoveryConfigFactory method getForeignSource.

@Override
public String getForeignSource(InetAddress address) {
    getReadLock().lock();
    try {
        LOG.debug("Looking for matching foreign source specific IP or IP range with address: {}...", address);
        List<Specific> specificCollection = getConfiguration().getSpecifics();
        for (Specific specific : specificCollection) {
            String ipAddr = specific.getAddress();
            if (ipAddr.equals(InetAddressUtils.str(address))) {
                String foreignSource = specific.getForeignSource().orElse(null);
                LOG.debug("Matched foreign source {} matching address: {} against specific {}.", foreignSource, address, ipAddr);
                return foreignSource;
            }
        }
        final byte[] laddr = address.getAddress();
        List<IncludeRange> includeRangeCollection = getConfiguration().getIncludeRanges();
        for (IncludeRange range : includeRangeCollection) {
            if (InetAddressUtils.isInetAddressInRange(laddr, range.getBegin(), range.getEnd())) {
                String foreignSource = range.getForeignSource().orElse(null);
                LOG.debug("Found foreign source {} with address {} in the range begin: {} and end: {}.", foreignSource, address, range.getBegin(), range.getEnd());
                return foreignSource;
            }
        }
        List<IncludeUrl> includeUrlCollection = getConfiguration().getIncludeUrls();
        for (IncludeUrl includeUrl : includeUrlCollection) {
            String ipAddr = includeUrl.getUrl().orElse("");
            if (ipAddr.equals(InetAddressUtils.str(address))) {
                String foreignSource = includeUrl.getForeignSource().orElse(null);
                LOG.debug("Matched foreign source {} matching address: {} in specified URL.", foreignSource, address);
                return foreignSource;
            }
        }
        return getConfiguration().getForeignSource().orElse(null);
    } finally {
        getReadLock().unlock();
    }
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) IncludeUrl(org.opennms.netmgt.config.discovery.IncludeUrl) Specific(org.opennms.netmgt.config.discovery.Specific)

Example 13 with Specific

use of org.opennms.netmgt.config.discovery.Specific in project opennms by OpenNMS.

the class DiscoveryRestService method getDiscoveryConfig.

private DiscoveryConfiguration getDiscoveryConfig(DiscoveryConfigurationDTO discoveryConfigurationDTO) {
    DiscoveryConfiguration discoveryConfiguration = new DiscoveryConfiguration();
    discoveryConfiguration.setTimeout(discoveryConfigurationDTO.getTimeout());
    discoveryConfiguration.setRetries(discoveryConfigurationDTO.getRetries());
    discoveryConfiguration.setForeignSource(discoveryConfigurationDTO.getForeignSource());
    discoveryConfiguration.setLocation(discoveryConfigurationDTO.getLocation());
    discoveryConfiguration.setChunkSize(discoveryConfigurationDTO.getChunkSize());
    for (DiscoveryConfigurationDTO.SpecificDTO specificDTO : discoveryConfigurationDTO.getSpecificDTOList()) {
        Specific specific = new Specific();
        specific.setAddress(specificDTO.getContent());
        specific.setTimeout(specificDTO.getTimeout());
        specific.setRetries(specificDTO.getRetries());
        specific.setForeignSource(specificDTO.getForeignSource());
        specific.setLocation(specificDTO.getLocation());
        discoveryConfiguration.addSpecific(specific);
    }
    for (DiscoveryConfigurationDTO.IncludeUrlDTO includeUrlDTO : discoveryConfigurationDTO.getIncludeUrlDTOList()) {
        IncludeUrl includeUrl = new IncludeUrl();
        includeUrl.setUrl(includeUrlDTO.getContent());
        includeUrl.setTimeout(includeUrlDTO.getTimeout());
        includeUrl.setRetries(includeUrlDTO.getRetries());
        includeUrl.setForeignSource(includeUrlDTO.getForeignSource());
        includeUrl.setLocation(includeUrlDTO.getLocation());
        discoveryConfiguration.addIncludeUrl(includeUrl);
    }
    for (DiscoveryConfigurationDTO.IncludeRangeDTO includeRangeDTO : discoveryConfigurationDTO.getIncludeRangeDTOList()) {
        IncludeRange includeRange = new IncludeRange();
        includeRange.setBegin(includeRangeDTO.getBegin());
        includeRange.setEnd(includeRangeDTO.getEnd());
        includeRange.setTimeout(includeRangeDTO.getTimeout());
        includeRange.setRetries(includeRangeDTO.getRetries());
        includeRange.setForeignSource(includeRangeDTO.getForeignSource());
        includeRange.setLocation(includeRangeDTO.getLocation());
        discoveryConfiguration.addIncludeRange(includeRange);
    }
    for (DiscoveryConfigurationDTO.ExcludeRangeDTO excludeRangeDTO : discoveryConfigurationDTO.getExcludeRangeDTOList()) {
        ExcludeRange excludeRange = new ExcludeRange();
        excludeRange.setBegin(excludeRangeDTO.getBegin());
        excludeRange.setEnd(excludeRangeDTO.getEnd());
        discoveryConfiguration.addExcludeRange(excludeRange);
    }
    return discoveryConfiguration;
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) IncludeUrl(org.opennms.netmgt.config.discovery.IncludeUrl) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) Specific(org.opennms.netmgt.config.discovery.Specific) ExcludeRange(org.opennms.netmgt.config.discovery.ExcludeRange)

Aggregations

Specific (org.opennms.netmgt.config.discovery.Specific)13 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)11 Test (org.junit.Test)8 IncludeRange (org.opennms.netmgt.config.discovery.IncludeRange)7 IncludeUrl (org.opennms.netmgt.config.discovery.IncludeUrl)6 List (java.util.List)5 ExcludeRange (org.opennms.netmgt.config.discovery.ExcludeRange)5 RequestDispatcher (javax.servlet.RequestDispatcher)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 File (java.io.File)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 LinkedList (java.util.LinkedList)1 IPAddress (org.opennms.core.network.IPAddress)1 ServiceRegistry (org.opennms.core.soa.ServiceRegistry)1 DiscoveryConfigFactory (org.opennms.netmgt.config.DiscoveryConfigFactory)1 DiscoveryTaskExecutor (org.opennms.netmgt.discovery.DiscoveryTaskExecutor)1 EventProxy (org.opennms.netmgt.events.api.EventProxy)1 IPPollAddress (org.opennms.netmgt.model.discovery.IPPollAddress)1