Search in sources :

Example 6 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class NewSuspectScanIT method testScanNewSuspectNoSnmp.

@Test(timeout = 300000)
public void testScanNewSuspectNoSnmp() 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.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), null, 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());
    // 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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 7 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class NewSuspectScanIT method testScanNewSuspectNoIpAddrTable.

@Test(timeout = 300000)
// 192.0.2.0/24 reserved by IANA for testing purposes
@JUnitSnmpAgent(host = "192.0.2.123", resource = "classpath:/no-ipaddrtable.properties")
public void testScanNewSuspectNoIpAddrTable() 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());
    InetAddress ip = addr("192.0.2.123");
    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(ip).getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_GAINED_SERVICE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(ip).setService("SNMP").getEvent());
    anticipator.anticipateEvent(new EventBuilder(EventConstants.REINITIALIZE_PRIMARY_SNMP_INTERFACE_EVENT_UEI, "Provisiond").setNodeid(nextNodeId).setInterface(ip).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 NewSuspectScan scan = m_provisioner.createNewSuspectScan(ip, null, null);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 2000, 0, 0);
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // 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(), 1, getMonitoredServiceDao().countAll());
    // Verify service count
    assertEquals(1, getServiceTypeDao().countAll());
    // Verify snmpInterface count
    assertEquals(0, getSnmpInterfaceDao().countAll());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) InetAddress(java.net.InetAddress) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 8 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator in project opennms by OpenNMS.

the class NewSuspectScanIT method testScanNewSuspectWithForeignSourceAndLocation.

@Test(timeout = 300000)
public void testScanNewSuspectWithForeignSourceAndLocation() 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.PROVISION_SCAN_COMPLETE_UEI, "Provisiond").setNodeid(nextNodeId).getEvent());
    final String foreignSource = "Testie";
    final String locationName = "!" + MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
    final NewSuspectScan scan = m_provisioner.createNewSuspectScan(addr("198.51.100.201"), foreignSource, locationName);
    runScan(scan);
    anticipator.verifyAnticipated(20000, 0, 0, 0, 0);
    // Verify distpoller count
    assertEquals(1, getDistPollerDao().countAll());
    // Verify node count
    assertEquals(1, getNodeDao().countAll());
    // 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());
    // HZN-960: Verify that the location name was properly set on the node in the requisition
    final Requisition requisition = m_foreignSourceRepository.getRequisition(foreignSource);
    final List<RequisitionNode> requisitionNodes = requisition.getNodes();
    assertEquals(1, requisitionNodes.size());
    final RequisitionNode requisitionNode = requisitionNodes.get(0);
    assertEquals(locationName, requisitionNode.getLocation());
}
Also used : RequisitionNode(org.opennms.netmgt.provision.persist.requisition.RequisitionNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition) EventAnticipator(org.opennms.netmgt.dao.mock.EventAnticipator) Test(org.junit.Test)

Example 9 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator 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 10 with EventAnticipator

use of org.opennms.netmgt.dao.mock.EventAnticipator 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 StringBuilder errorMsg = new StringBuilder();
    // 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)

Aggregations

EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)22 Test (org.junit.Test)18 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)12 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 Event (org.opennms.netmgt.xml.event.Event)7 InetAddress (java.net.InetAddress)6 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)4 Date (java.util.Date)2 DiscoveryConfiguration (org.opennms.netmgt.config.discovery.DiscoveryConfiguration)2 IncludeRange (org.opennms.netmgt.config.discovery.IncludeRange)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 Parm (org.opennms.netmgt.xml.event.Parm)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 BigInteger (java.math.BigInteger)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Before (org.junit.Before)1 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)1 DiscoveryConfigFactory (org.opennms.netmgt.config.DiscoveryConfigFactory)1