Search in sources :

Example 6 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class ProvisionerIT method testPopulateWithIpv6SnmpAndNodeScan.

// fail if we take more than five minutes
@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "10.1.15.245", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "10.3.20.23", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "2001:0470:e2f1:cafe:16c1:7cff:12d6:7bb9", resource = "classpath:/snmpwalk-demo.properties") })
public void testPopulateWithIpv6SnmpAndNodeScan() throws Exception {
    final ForeignSource fs = new ForeignSource();
    fs.setName("matt:");
    fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
    m_foreignSourceRepository.putDefaultForeignSource(fs);
    importFromResource("classpath:/requisition_then_scanv6.xml", Boolean.TRUE.toString());
    //Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    //Verify node count
    assertEquals(1, getNodeDao().countAll());
    //Verify ipinterface count
    assertEquals(1, getInterfaceDao().countAll());
    //Verify ifservices count
    assertEquals(1, getMonitoredServiceDao().countAll());
    //Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    //Verify snmpInterface count
    assertEquals(1, getSnmpInterfaceDao().countAll());
    runPendingScans();
    //Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    //Verify node count
    assertEquals(1, getNodeDao().countAll());
    //Verify ipinterface count
    assertEquals("Unexpected number of IP interfaces found: " + getInterfaceDao().findAll(), 3, getInterfaceDao().countAll());
    //Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 3, getMonitoredServiceDao().countAll());
    //Verify service count
    assertEquals("Unexpected number of service types found: " + getServiceTypeDao().findAll(), 1, getServiceTypeDao().countAll());
    //Verify snmpInterface count
    assertEquals("Unexpected number of SNMP interfaces found: " + getSnmpInterfaceDao().findAll(), 6, getSnmpInterfaceDao().countAll());
    // Ensure that collection is on for all ip interfaces
    for (OnmsIpInterface iface : getInterfaceDao().findAll()) {
        OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
        assertNotNull("Expected an snmp interface associated with " + iface.getIpAddress(), snmpIface);
        assertTrue("Expected snmp interface associated with " + iface.getIpAddress() + " to have collection enabled.", snmpIface.isCollectionEnabled());
    }
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 7 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FilesystemForeignSourceRepositoryTest method createForeignSource.

private ForeignSource createForeignSource(String foreignSource) throws Exception {
    ForeignSource fs = new ForeignSource(foreignSource);
    fs.addDetector(new PluginConfig("HTTP", "org.opennms.netmgt.provision.detector.simple.HttpDetector"));
    fs.addPolicy(new PluginConfig("all-ipinterfaces", "org.opennms.netmgt.provision.persist.policies.InclusiveInterfacePolicy"));
    m_foreignSourceRepository.save(fs);
    m_foreignSourceRepository.flush();
    return fs;
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)

Example 8 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FilesystemForeignSourceRepositoryTest method testForeignSource.

@Test
public void testForeignSource() throws Exception {
    createRequisition();
    ForeignSource foreignSource = createForeignSource(m_defaultForeignSourceName);
    Set<ForeignSource> foreignSources = m_foreignSourceRepository.getForeignSources();
    assertEquals("number of foreign sources must be 1", 1, foreignSources.size());
    assertEquals("getAll() foreign source name must match", m_defaultForeignSourceName, foreignSources.iterator().next().getName());
    // check that the foreign source matches
    final ForeignSource newForeignSource = m_foreignSourceRepository.getForeignSource(m_defaultForeignSourceName);
    assertEquals(foreignSource.getName(), newForeignSource.getName());
    assertEquals(foreignSource.getDateStampAsDate(), newForeignSource.getDateStampAsDate());
    assertEquals(foreignSource.getDetectorNames(), newForeignSource.getDetectorNames());
    assertEquals(foreignSource.getScanInterval(), newForeignSource.getScanInterval());
}
Also used : ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Test(org.junit.Test)

Example 9 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FilesystemForeignSourceRepositoryTest method testDefaultForeignSource.

@Test
public void testDefaultForeignSource() throws Exception {
    createRequisition();
    List<String> detectorList = Arrays.asList(new String[] { "DNS", "FTP", "HTTP", "HTTPS", "ICMP", "IMAP", "LDAP", "NRPE", "POP3", "SMTP", "SNMP", "SSH" });
    String uuid = UUID.randomUUID().toString();
    ForeignSource defaultForeignSource = m_foreignSourceRepository.getForeignSource(uuid);
    assertEquals("name must match requested foreign source repository name", uuid, defaultForeignSource.getName());
    assertEquals("scan-interval must be 1 day", 86400000, defaultForeignSource.getScanInterval().getMillis());
    assertEquals("foreign source must have no default policies", 0, defaultForeignSource.getPolicies().size());
    List<String> fsNames = new ArrayList<String>();
    for (PluginConfig config : defaultForeignSource.getDetectors()) {
        fsNames.add(config.getName());
    }
    assertEquals("detector list must match expected defaults", detectorList, fsNames);
    assertTrue("foreign source must be tagged as default", defaultForeignSource.isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with ForeignSource

use of org.opennms.netmgt.provision.persist.foreignsource.ForeignSource in project opennms by OpenNMS.

the class FusedForeignSourceRepositoryTest method integrationTest.

@Test
public void integrationTest() {
    /*
         * First, the user creates a requisition in the UI, or RESTful
         * interface.
         */
    Requisition pendingReq = new Requisition("test");
    pendingReq.putNode(createNode("1"));
    m_pending.save(pendingReq);
    m_pending.flush();
    /* 
         * Then, the user makes a foreign source configuration to go along
         * with that requisition.
         */
    ForeignSource pendingSource = m_repository.getForeignSource("test");
    assertTrue(pendingSource.isDefault());
    pendingSource.setDetectors(new ArrayList<PluginConfig>());
    m_pending.save(pendingSource);
    m_pending.flush();
    /*
         * Now we got an import event, so we import that requisition file,
         * and save it.  The ForeignSource in the pending repository should
         * match the one in the active one, now.
         */
    Requisition activeReq = m_repository.importResourceRequisition(new UrlResource(m_pending.getRequisitionURL("test")));
    ForeignSource activeSource = m_active.getForeignSource("test");
    // and the foreign source should be the same as the one we made earlier, only this time it's active
    assertEquals(activeSource.getName(), pendingSource.getName());
    assertEquals(activeSource.getDetectorNames(), pendingSource.getDetectorNames());
    assertEquals(activeSource.getScanInterval(), pendingSource.getScanInterval());
    assertRequisitionsMatch("active and pending requisitions should match", activeReq, pendingReq);
    /*
         * Since it's been officially deployed, the requisition and foreign
         * source should no longer be in the pending repo.
         */
    assertNull("the requisition should be null in the pending repo", m_pending.getRequisition("test"));
    assertTrue("the foreign source should be default since there's no specific in the pending repo", m_pending.getForeignSource("test").isDefault());
}
Also used : PluginConfig(org.opennms.netmgt.provision.persist.foreignsource.PluginConfig) UrlResource(org.springframework.core.io.UrlResource) ForeignSource(org.opennms.netmgt.provision.persist.foreignsource.ForeignSource) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) Test(org.junit.Test)

Aggregations

ForeignSource (org.opennms.netmgt.provision.persist.foreignsource.ForeignSource)72 PluginConfig (org.opennms.netmgt.provision.persist.foreignsource.PluginConfig)31 Test (org.junit.Test)23 Requisition (org.opennms.netmgt.provision.persist.requisition.Requisition)11 Before (org.junit.Before)10 MockForeignSourceRepository (org.opennms.netmgt.provision.persist.MockForeignSourceRepository)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Transactional (org.springframework.transaction.annotation.Transactional)8 TreeSet (java.util.TreeSet)6 File (java.io.File)4 DELETE (javax.ws.rs.DELETE)4 Date (java.util.Date)3 Consumes (javax.ws.rs.Consumes)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2