use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryConfigFactoryTest method testSingleIPExclude.
@Test
public void testSingleIPExclude() throws Exception {
final DiscoveryConfiguration conf = new DiscoveryConfiguration();
IncludeRange ir = new IncludeRange();
ir.setBegin("192.168.0.1");
ir.setEnd("192.168.0.254");
conf.addIncludeRange(ir);
ExcludeRange er = new ExcludeRange();
er.setBegin("192.168.0.100");
er.setEnd("192.168.0.100");
conf.addExcludeRange(er);
DiscoveryConfigFactory factory = new DiscoveryConfigFactory(conf);
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.1")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.2")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.99")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.0.100")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.101")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.151")));
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryConfigFactoryTest method testMultipleExcludes.
@Test
public void testMultipleExcludes() throws Exception {
final DiscoveryConfiguration conf = new DiscoveryConfiguration();
IncludeRange ir = new IncludeRange();
ir.setBegin("192.168.0.1");
ir.setEnd("192.168.0.254");
conf.addIncludeRange(ir);
ir = new IncludeRange();
ir.setBegin("192.168.2.1");
ir.setEnd("192.168.2.255");
conf.addIncludeRange(ir);
Specific s = new Specific();
s.setAddress("192.168.1.1");
conf.addSpecific(s);
s = new Specific();
s.setAddress("192.168.4.1");
conf.addSpecific(s);
ExcludeRange er = new ExcludeRange();
er.setBegin("192.168.0.100");
er.setEnd("192.168.0.150");
conf.addExcludeRange(er);
er = new ExcludeRange();
er.setBegin("192.168.2.200");
er.setEnd("192.168.4.254");
conf.addExcludeRange(er);
final DiscoveryConfigFactory factory = new DiscoveryConfigFactory(conf);
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.1")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.2")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.99")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.0.100")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.0.140")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.0.150")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.0.151")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.1.1")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.2.1")));
assertFalse(factory.isExcluded(InetAddressUtils.addr("192.168.2.100")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.2.200")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.2.220")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.2.255")));
assertTrue(factory.isExcluded(InetAddressUtils.addr("192.168.4.1")));
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryConfigurationLocationMigratorOfflineTest method testRemoveAttribute.
@Test
public void testRemoveAttribute() throws Exception {
final DiscoveryConfigurationLocationMigratorOffline task = new DiscoveryConfigurationLocationMigratorOffline();
task.preExecute();
task.execute();
task.postExecute();
final File configFile = new File(m_tempFolder.getRoot(), "etc/discovery-configuration.xml");
final DiscoveryConfiguration discoveryConfiguration = JaxbUtils.unmarshal(DiscoveryConfiguration.class, new FileReader(configFile));
Assert.assertNotNull(discoveryConfiguration);
Assert.assertEquals(3, discoveryConfiguration.getIncludeRanges().size());
Assert.assertEquals(3, discoveryConfiguration.getExcludeRanges().size());
Assert.assertEquals(3, discoveryConfiguration.getSpecifics().size());
Assert.assertEquals(3, discoveryConfiguration.getIncludeUrls().size());
int pittsboroLocation = 0;
int oldDefaultLocation = 0;
int newDefaultLocation = 0;
int nullLocation = 0;
for (IncludeRange e : discoveryConfiguration.getIncludeRanges()) {
if (DiscoveryConfigurationLocationMigratorOffline.NEW_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
newDefaultLocation++;
}
if (DiscoveryConfigurationLocationMigratorOffline.OLD_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
oldDefaultLocation++;
}
if (!e.getLocation().isPresent()) {
nullLocation++;
}
if ("pittsboro".equals(e.getLocation().orElse(null))) {
pittsboroLocation++;
}
}
Assert.assertEquals(1, newDefaultLocation);
Assert.assertEquals(1, pittsboroLocation);
Assert.assertEquals(1, nullLocation);
Assert.assertEquals(0, oldDefaultLocation);
pittsboroLocation = 0;
oldDefaultLocation = 0;
newDefaultLocation = 0;
nullLocation = 0;
for (Specific e : discoveryConfiguration.getSpecifics()) {
if (DiscoveryConfigurationLocationMigratorOffline.NEW_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
newDefaultLocation++;
}
if (DiscoveryConfigurationLocationMigratorOffline.OLD_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
oldDefaultLocation++;
}
if (!e.getLocation().isPresent()) {
nullLocation++;
}
if ("pittsboro".equals(e.getLocation().orElse(null))) {
pittsboroLocation++;
}
}
Assert.assertEquals(1, newDefaultLocation);
Assert.assertEquals(1, pittsboroLocation);
Assert.assertEquals(1, nullLocation);
Assert.assertEquals(0, oldDefaultLocation);
pittsboroLocation = 0;
oldDefaultLocation = 0;
newDefaultLocation = 0;
nullLocation = 0;
for (IncludeUrl e : discoveryConfiguration.getIncludeUrls()) {
if (DiscoveryConfigurationLocationMigratorOffline.NEW_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
newDefaultLocation++;
}
if (DiscoveryConfigurationLocationMigratorOffline.OLD_DEFAULT_LOCATION.equals(e.getLocation().orElse(null))) {
oldDefaultLocation++;
}
if (!e.getLocation().isPresent()) {
nullLocation++;
}
if ("pittsboro".equals(e.getLocation().orElse(null))) {
pittsboroLocation++;
}
}
Assert.assertEquals(1, newDefaultLocation);
Assert.assertEquals(1, pittsboroLocation);
Assert.assertEquals(1, nullLocation);
Assert.assertEquals(0, oldDefaultLocation);
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class DiscoveryConfigurationMigratorOfflineTest method testRemoveAttribute.
@Test
public void testRemoveAttribute() throws Exception {
final DiscoveryConfigurationMigratorOffline task = new DiscoveryConfigurationMigratorOffline();
task.preExecute();
task.execute();
task.postExecute();
final File configFile = new File(m_tempFolder.getRoot(), "etc/discovery-configuration.xml");
final DiscoveryConfiguration config = JaxbUtils.unmarshal(DiscoveryConfiguration.class, configFile);
Assert.assertNotNull(config);
Assert.assertEquals(1, config.getIncludeRanges().size());
}
use of org.opennms.netmgt.config.discovery.DiscoveryConfiguration in project opennms by OpenNMS.
the class RangeChunkerTest method testConsecutiveSpecificsWithDifferentForeignSources.
@Test
public void testConsecutiveSpecificsWithDifferentForeignSources() {
DiscoveryConfiguration config = new DiscoveryConfiguration();
for (int i = 0; i < 5; i++) {
Specific specific = new Specific();
specific.setAddress("10.0.0." + i);
specific.setForeignSource(i % 2 == 0 ? "ABC" : "DEF");
specific.setLocation("123");
specific.setRetries(1);
specific.setTimeout(1000l);
config.addSpecific(specific);
}
Map<String, List<DiscoveryJob>> jobs = new RangeChunker(ipAddressFilter).chunk(config);
printJobs(jobs);
assertEquals(2, jobs.get("123").size());
assertEquals(3, jobs.get("123").get(0).getRanges().size());
assertEquals(2, jobs.get("123").get(1).getRanges().size());
}
Aggregations