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());
}
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();
}
}
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;
}
Aggregations