Search in sources :

Example 21 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents 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)

Example 22 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents 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 23 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class IfIndexNullIT method testNullIfIndex.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = "192.0.2.201", port = 161, resource = "classpath:/snmpTestData-null.properties"), @JUnitSnmpAgent(host = "192.0.2.204", port = 161, resource = "classpath:/snmpTestData-null.properties") })
public void testNullIfIndex() throws Exception {
    final CountDownLatch eventRecieved = anticipateEvents(1, EventConstants.PROVISION_SCAN_COMPLETE_UEI, EventConstants.PROVISION_SCAN_ABORTED_UEI);
    m_provisioner.importModelFromResource(m_resourceLoader.getResource("classpath:/tec_dump.xml"), Boolean.TRUE.toString());
    waitForEverything();
    final List<OnmsNode> nodes = getNodeDao().findAll();
    final OnmsNode node = nodes.get(0);
    eventRecieved.await();
    final NodeScan scan = m_provisioner.createNodeScan(node.getId(), node.getForeignSource(), node.getForeignId(), node.getLocation());
    runScan(scan);
    // Verify ipinterface count
    assertEquals(2, getInterfaceDao().countAll());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 24 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testDot1dStpPortTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = DLINK1_IP, port = 161, resource = DLINK1_SNMP_RESOURCE) })
public void testDot1dStpPortTableWalk() throws Exception {
    String trackerName = "dot1dbaseStpTable";
    final List<BridgeStpLink> links = new ArrayList<>();
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(DLINK1_IP));
    Dot1dStpPortTableTracker tracker = new Dot1dStpPortTableTracker() {

        @Override
        public void processDot1dStpPortRow(final Dot1dStpPortRow row) {
            links.add(row.getLink());
        }
    };
    try {
        m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(26, links.size());
    int i = 0;
    for (BridgeStpLink link : links) {
        assertEquals(++i, link.getStpPort().intValue());
        assertEquals(128, link.getStpPortPriority().intValue());
        if (link.getStpPort() <= 6 || link.getStpPort() == 24)
            assertEquals(BridgeDot1dStpPortState.DOT1D_STP_PORT_STATUS_FORWARDING, link.getStpPortState());
        else
            assertEquals(BridgeDot1dStpPortState.DOT1D_STP_PORT_STATUS_DISABLED, link.getStpPortState());
        assertEquals(BridgeDot1dStpPortEnable.DOT1D_STP_PORT_ENABLED, link.getStpPortEnable());
        assertEquals(2000000, link.getStpPortPathCost().intValue());
        assertEquals("0000000000000000", link.getDesignatedRoot());
        assertEquals(0, link.getDesignatedCost().intValue());
        assertEquals("0000000000000000", link.getDesignatedBridge());
        assertEquals("0000", link.getDesignatedPort());
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BridgeStpLink(org.opennms.netmgt.model.BridgeStpLink) ArrayList(java.util.ArrayList) Dot1dStpPortTableTracker(org.opennms.netmgt.enlinkd.snmp.Dot1dStpPortTableTracker) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Example 25 with JUnitSnmpAgents

use of org.opennms.core.test.snmp.annotations.JUnitSnmpAgents in project opennms by OpenNMS.

the class EnLinkdSnmpIT method testIsisISAdjTableWalk.

@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = SIEGFRIE_IP, port = 161, resource = SIEGFRIE_SNMP_RESOURCE) })
public void testIsisISAdjTableWalk() throws Exception {
    final List<IsIsLink> links = new ArrayList<>();
    String trackerName = "isisISAdjTable";
    SnmpAgentConfig config = SnmpPeerFactory.getInstance().getAgentConfig(InetAddress.getByName(SIEGFRIE_IP));
    IsisISAdjTableTracker tracker = new IsisISAdjTableTracker() {

        public void processIsisAdjRow(final IsIsAdjRow row) {
            assertEquals(5, row.getColumnCount());
            links.add(row.getIsisLink());
        }
    };
    try {
        m_client.walk(config, tracker).withDescription(trackerName).withLocation(null).execute().get();
    } catch (final InterruptedException e) {
        LOG.error("run: collection interrupted, exiting", e);
        return;
    }
    assertEquals(2, links.size());
    for (final IsIsLink link : links) {
        assertEquals(1, link.getIsisISAdjIndex().intValue());
        assertEquals(IsisISAdjState.up, link.getIsisISAdjState());
        assertEquals(IsisISAdjNeighSysType.l1_IntermediateSystem, link.getIsisISAdjNeighSysType());
        assertEquals(0, link.getIsisISAdjNbrExtendedCircID().intValue());
        if (link.getIsisCircIndex().intValue() == 533) {
            assertEquals("001f12accbf0", link.getIsisISAdjNeighSNPAAddress());
            assertEquals("000110255062", link.getIsisISAdjNeighSysID());
        } else if (link.getIsisCircIndex().intValue() == 552) {
            assertEquals("0021590e47c2", link.getIsisISAdjNeighSNPAAddress());
            assertEquals("000110088500", link.getIsisISAdjNeighSysID());
        } else {
            assertEquals(true, false);
        }
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) IsIsLink(org.opennms.netmgt.model.IsIsLink) ArrayList(java.util.ArrayList) IsisISAdjTableTracker(org.opennms.netmgt.enlinkd.snmp.IsisISAdjTableTracker) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)66 Test (org.junit.Test)64 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)23 LldpLink (org.opennms.netmgt.model.LldpLink)14 ArrayList (java.util.ArrayList)8 BridgeMacLink (org.opennms.netmgt.model.BridgeMacLink)8 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)6 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)4 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 CdpLink (org.opennms.netmgt.model.CdpLink)4 IsIsLink (org.opennms.netmgt.model.IsIsLink)4 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 LldpElement (org.opennms.netmgt.model.LldpElement)3 OspfLink (org.opennms.netmgt.model.OspfLink)3 InetAddress (java.net.InetAddress)2 CdpGlobalGroupTracker (org.opennms.netmgt.enlinkd.snmp.CdpGlobalGroupTracker)2 LldpLocalGroupTracker (org.opennms.netmgt.enlinkd.snmp.LldpLocalGroupTracker)2 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)2