Search in sources :

Example 21 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NewSuspectScanIT method testRescanWithChangingDns.

@Test(timeout = 300000)
public void testRescanWithChangingDns() throws Exception {
    final HostnameResolver originalHostnameResolver = m_provisionService.getHostnameResolver();
    try {
        final int nextNodeId = m_nodeDao.getNextNodeId();
        //Verify empty database
        assertEquals(1, getDistPollerDao().countAll());
        assertEquals(0, getNodeDao().countAll());
        assertEquals(0, getInterfaceDao().countAll());
        assertEquals(0, getMonitoredServiceDao().countAll());
        assertEquals(0, getServiceTypeDao().countAll());
        assertEquals(0, getSnmpInterfaceDao().countAll());
        m_provisionService.setHostnameResolver(new HostnameResolver() {

            @Override
            public String getHostname(final InetAddress addr, final String location) {
                return "oldNodeLabel";
            }
        });
        final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
        anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
        anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
        anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
        final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, null);
        runScan(scan);
        anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
        //Verify distpoller count
        assertEquals(1, getDistPollerDao().countAll());
        //Verify node count
        assertEquals(1, getNodeDao().countAll());
        //Verify node info
        final OnmsNode beforeNode = getNodeDao().findAll().iterator().next();
        assertEquals(Integer.valueOf(nextNodeId), beforeNode.getId());
        assertEquals("oldNodeLabel", beforeNode.getLabel());
        assertEquals(NodeLabelSource.HOSTNAME, beforeNode.getLabelSource());
        assertEquals(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, beforeNode.getLocation().getLocationName());
        assertEquals("oldNodeLabel", beforeNode.getIpInterfaces().iterator().next().getIpHostName());
        //Verify ipinterface count
        assertEquals("Unexpected number of interfaces found: " + getInterfaceDao().findAll(), 1, getInterfaceDao().countAll());
        //Verify ifservices count - discover snmp service on other if
        assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 0, getMonitoredServiceDao().countAll());
        //Verify service count
        assertEquals(0, getServiceTypeDao().countAll());
        //Verify snmpInterface count
        assertEquals(0, getSnmpInterfaceDao().countAll());
        m_provisionService.setHostnameResolver(new HostnameResolver() {

            @Override
            public String getHostname(final InetAddress addr, final String location) {
                return "newNodeLabel";
            }
        });
        final ForceRescanScan rescan = m_provisioner.createForceRescanScan(nextNodeId);
        runScan(rescan);
        final OnmsNode afterNode = getNodeDao().findAll().iterator().next();
        assertEquals(Integer.valueOf(nextNodeId), afterNode.getId());
        assertEquals("newNodeLabel", afterNode.getLabel());
        assertEquals(NodeLabelSource.HOSTNAME, afterNode.getLabelSource());
        assertEquals("newNodeLabel", afterNode.getIpInterfaces().iterator().next().getIpHostName());
    } finally {
        m_provisionService.setHostnameResolver(originalHostnameResolver);
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 22 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NewSuspectScanIT method testWithNoDnsOnRescan.

@Test(timeout = 300000)
public void testWithNoDnsOnRescan() throws Exception {
    try {
        final int nextNodeId = m_nodeDao.getNextNodeId();
        //Verify empty database
        assertEquals(1, getDistPollerDao().countAll());
        assertEquals(0, getNodeDao().countAll());
        assertEquals(0, getInterfaceDao().countAll());
        assertEquals(0, getMonitoredServiceDao().countAll());
        assertEquals(0, getServiceTypeDao().countAll());
        assertEquals(0, getSnmpInterfaceDao().countAll());
        m_provisionService.setHostnameResolver(new HostnameResolver() {

            @Override
            public String getHostname(final InetAddress addr, final String location) {
                return "oldNodeLabel";
            }
        });
        final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
        anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
        anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
        anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
        final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, null);
        runScan(scan);
        anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
        //Verify distpoller count
        assertEquals(1, getDistPollerDao().countAll());
        //Verify node count
        assertEquals(1, getNodeDao().countAll());
        //Verify node info
        final OnmsNode beforeNode = getNodeDao().findAll().iterator().next();
        assertEquals(Integer.valueOf(nextNodeId), beforeNode.getId());
        assertEquals("oldNodeLabel", beforeNode.getLabel());
        assertEquals(NodeLabelSource.HOSTNAME, beforeNode.getLabelSource());
        assertEquals("oldNodeLabel", beforeNode.getIpInterfaces().iterator().next().getIpHostName());
        //Verify ipinterface count
        assertEquals("Unexpected number of interfaces found: " + getInterfaceDao().findAll(), 1, getInterfaceDao().countAll());
        //Verify ifservices count - discover snmp service on other if
        assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 0, getMonitoredServiceDao().countAll());
        //Verify service count
        assertEquals(0, getServiceTypeDao().countAll());
        //Verify snmpInterface count
        assertEquals(0, getSnmpInterfaceDao().countAll());
        m_provisionService.setHostnameResolver(new HostnameResolver() {

            @Override
            public String getHostname(final InetAddress addr, final String location) {
                return null;
            }
        });
        final ForceRescanScan rescan = m_provisioner.createForceRescanScan(nextNodeId);
        runScan(rescan);
        final OnmsNode afterNode = getNodeDao().findAll().iterator().next();
        assertEquals(Integer.valueOf(nextNodeId), afterNode.getId());
        assertEquals("oldNodeLabel", afterNode.getLabel());
        assertEquals(NodeLabelSource.HOSTNAME, afterNode.getLabelSource());
        assertEquals("oldNodeLabel", afterNode.getIpInterfaces().iterator().next().getIpHostName());
    } finally {
        m_provisionService.setHostnameResolver(new DefaultHostnameResolver(m_locationAwareDnsLookupClient));
    }
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 23 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class MultipleImportIT method testScanTwice.

@Test
@Ignore
@JUnitSnmpAgent(host = "0.0.0.0", resource = "classpath:/snmpwalk-empty.properties")
public void testScanTwice() throws Exception {
    final String[] ueis = { EventConstants.PROVISION_SCAN_COMPLETE_UEI, EventConstants.PROVISION_SCAN_ABORTED_UEI };
    final CountDownLatch eventReceived = anticipateEvents(1, ueis);
    System.err.println("triggering first import");
    m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/SPC-222-a.xml"), Boolean.TRUE.toString());
    waitForEverything();
    System.err.println("triggering second import");
    m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/SPC-222-b.xml"), Boolean.TRUE.toString());
    waitForEverything();
    System.err.println("finished triggering imports");
    eventReceived.await(5, TimeUnit.MINUTES);
    final List<OnmsNode> nodes = getNodeDao().findAll();
    assertEquals(200, nodes.size());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CountDownLatch(java.util.concurrent.CountDownLatch) Ignore(org.junit.Ignore) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 24 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class NewSuspectScanIT method testScanNewSuspectWithForeignSource.

@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "198.51.100.201", resource = "classpath:/snmpTestData3.properties"), @JUnitSnmpAgent(host = "198.51.100.204", resource = "classpath:/snmpTestData3.properties") })
public void testScanNewSuspectWithForeignSource() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    //Verify empty database
    assertEquals(1, getDistPollerDao().countAll());
    assertEquals(0, getNodeDao().countAll());
    assertEquals(0, getInterfaceDao().countAll());
    assertEquals(0, getMonitoredServiceDao().countAll());
    assertEquals(0, getServiceTypeDao().countAll());
    assertEquals(0, getSnmpInterfaceDao().countAll());
    final EventAnticipator anticipator = m_eventSubscriber.getEventAnticipator();
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.204")).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(addr("198.51.100.201")).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    final String foreignSource = "Testie";
    NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
    //Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    //Verify node count
    assertEquals(1, getNodeDao().countAll());
    List<OnmsNode> onmsNodes = getNodeDao().findByLabel("brozow.local");
    OnmsNode onmsNode = onmsNodes.get(0);
    assertEquals("Testie", onmsNode.getForeignSource());
    assertEquals(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID, onmsNode.getLocation().getLocationName());
    final StringBuffer errorMsg = new StringBuffer();
    //Verify ipinterface count
    for (final OnmsIpInterface iface : getInterfaceDao().findAll()) {
        errorMsg.append(iface.toString());
    }
    assertEquals(errorMsg.toString(), 2, getInterfaceDao().countAll());
    //Verify ifservices count - discover snmp service on other if
    assertEquals("Unexpected number of services found.", 2, getMonitoredServiceDao().countAll());
    //Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    //Verify snmpInterface count
    assertEquals(6, getSnmpInterfaceDao().countAll());
    // NMS-8835: Now send another new suspect event for the same IP address and foreignSource
    scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID);
    runScan(scan);
    // The node count should not increase
    assertEquals(1, getNodeDao().countAll());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 25 with OnmsNode

use of org.opennms.netmgt.model.OnmsNode in project opennms by OpenNMS.

the class ProvisionerIT method testProvisionerServiceRescanAfterAddingSnmpNms7838.

// fail if we take more than five minutes
@Test(timeout = 300000)
// Start the test with an empty SNMP agent
@JUnitSnmpAgent(host = "198.51.100.201", port = 161, resource = "classpath:/snmpwalk-empty.properties")
public void testProvisionerServiceRescanAfterAddingSnmpNms7838() throws Exception {
    importFromResource("classpath:/requisition_then_scan2.xml", Boolean.TRUE.toString());
    final List<OnmsNode> nodes = getNodeDao().findAll();
    final OnmsNode node = nodes.get(0);
    runPendingScans();
    m_nodeDao.flush();
    assertEquals(1, getInterfaceDao().countAll());
    // Make sure that the OnmsIpInterface doesn't have an ifIndex
    assertNull(getInterfaceDao().get(node, "198.51.100.201").getIfIndex());
    // Make sure that no OnmsSnmpInterface records exist for the node
    assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 4));
    assertNull(getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 5));
    LOG.info("******************** ADDING SNMP DATA ********************");
    // Add some SNMP data to the agent
    m_mockSnmpDataProvider.setDataForAddress(new SnmpAgentAddress(addr("198.51.100.201"), 161), new DefaultResourceLoader().getResource("classpath:/snmpTestData3.properties"));
    // Rescan
    m_mockEventIpcManager.sendEventToListeners(nodeUpdated(node.getId()));
    runPendingScans();
    m_nodeDao.flush();
    // Make sure that a second interface was added from the SNMP agent data
    assertEquals(2, getInterfaceDao().countAll());
    // Verify the ifIndex entries
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getIfIndex().intValue());
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.201").getSnmpInterface().getIfIndex().intValue());
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getIfIndex().intValue());
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.204").getSnmpInterface().getIfIndex().intValue());
}
Also used : SnmpAgentAddress(org.opennms.netmgt.snmp.SnmpAgentAddress) OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Aggregations

OnmsNode (org.opennms.netmgt.model.OnmsNode)438 Test (org.junit.Test)187 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)99 Transactional (org.springframework.transaction.annotation.Transactional)76 ArrayList (java.util.ArrayList)48 Date (java.util.Date)40 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)38 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)36 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)31 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)31 InetAddress (java.net.InetAddress)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)28 Before (org.junit.Before)27 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)26 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)26 File (java.io.File)24 HashMap (java.util.HashMap)23 List (java.util.List)21 Path (javax.ws.rs.Path)21 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)20