Search in sources :

Example 1 with DiscoveryConfiguration

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")));
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) ExcludeRange(org.opennms.netmgt.config.discovery.ExcludeRange) Test(org.junit.Test)

Example 2 with DiscoveryConfiguration

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")));
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) Specific(org.opennms.netmgt.config.discovery.Specific) ExcludeRange(org.opennms.netmgt.config.discovery.ExcludeRange) Test(org.junit.Test)

Example 3 with DiscoveryConfiguration

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);
}
Also used : IncludeRange(org.opennms.netmgt.config.discovery.IncludeRange) IncludeUrl(org.opennms.netmgt.config.discovery.IncludeUrl) DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) FileReader(java.io.FileReader) Specific(org.opennms.netmgt.config.discovery.Specific) File(java.io.File) Test(org.junit.Test)

Example 4 with DiscoveryConfiguration

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());
}
Also used : DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) File(java.io.File) Test(org.junit.Test)

Example 5 with DiscoveryConfiguration

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());
}
Also used : DiscoveryConfiguration(org.opennms.netmgt.config.discovery.DiscoveryConfiguration) List(java.util.List) Specific(org.opennms.netmgt.config.discovery.Specific) Test(org.junit.Test)

Aggregations

DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)18 Test (org.junit.Test)12 Specific (org.opennms.netmgt.config.discovery.Specific)11 IncludeRange (org.opennms.netmgt.config.discovery.IncludeRange)9 List (java.util.List)6 ExcludeRange (org.opennms.netmgt.config.discovery.ExcludeRange)6 IncludeUrl (org.opennms.netmgt.config.discovery.IncludeUrl)5 DiscoveryConfigFactory (org.opennms.netmgt.config.DiscoveryConfigFactory)4 ServletException (javax.servlet.ServletException)3 File (java.io.File)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 HttpSession (javax.servlet.http.HttpSession)2 IPAddress (org.opennms.core.network.IPAddress)2 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)2 DiscoveryTaskExecutor (org.opennms.netmgt.discovery.DiscoveryTaskExecutor)2 IPPollRange (org.opennms.netmgt.model.discovery.IPPollRange)2 Event (org.opennms.netmgt.xml.event.Event)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 FileReader (java.io.FileReader)1