Search in sources :

Example 16 with JUnitSnmpAgent

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

the class InstanceStrategyIntegrationTest method testAgentTimeout.

/*
     * Test the poller's behaviour when the SNMP agent times outs. Verify:
     * That the proper events are sent by the daemon. The AP state in the
     * database after the poll.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testAgentTimeout() throws Exception {
    // Add AP1 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    // Add a controller to the default package
    addNewController("amc1", "10.1.0.2", "default");
    // Set AP1 as UP
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Make the SNMP agent timeout
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.getInetAddress("10.1.0.2"));
    Sleeper.getInstance().setSleepTime(agentConfig.getTimeout() + 1000);
    try {
        // Anticipate the event
        anticipateApStatusEvent(AP1_MAC, "DOWN");
        // Initialize and start the daemon
        initApmdWithConfig(getStandardConfig());
        m_apm.start();
        // Verify the events
        verifyAnticipated(POLLING_INTERVAL_DELTA + 2000);
        // Verify the state of the AP in the database
        OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
        assertTrue(ap1.getStatus() == AccessPointStatus.OFFLINE);
    } finally {
        // Clear the timeout
        Sleeper.getInstance().setSleepTime(0);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 17 with JUnitSnmpAgent

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

the class ProvisionerIT method testIfIndexChangeNms6567.

// fail if we take more than five minutes
@Test(timeout = 300000)
@JUnitSnmpAgent(host = "198.51.100.201", port = 161, resource = "classpath:/snmpTestData3.properties")
public void testIfIndexChangeNms6567() 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(2, getInterfaceDao().countAll());
    // Verify the initial state of the ifIndex values
    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());
    // This is a pretty pedantic check :)
    assertEquals(4, getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 4).getIfIndex().intValue());
    assertEquals(5, getSnmpInterfaceDao().findByNodeIdAndIfIndex(node.getId(), 5).getIfIndex().intValue());
    // Swap the ifIndex values for the two interfaces
    m_mockSnmpDataProvider.updateIntValue(new SnmpAgentAddress(InetAddressUtils.addr("198.51.100.201"), 161), ".1.3.6.1.2.1.4.20.1.2.198.51.100.201", 4);
    m_mockSnmpDataProvider.updateIntValue(new SnmpAgentAddress(InetAddressUtils.addr("198.51.100.201"), 161), ".1.3.6.1.2.1.4.20.1.2.198.51.100.204", 5);
    // Rescan
    m_mockEventIpcManager.sendEventToListeners(nodeUpdated(node.getId()));
    runPendingScans();
    m_nodeDao.flush();
    assertEquals(2, getInterfaceDao().countAll());
    // Verify that the ifIndex fields on the interfaces have been updated
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.201").getIfIndex().intValue());
    assertEquals(4, getInterfaceDao().get(node, "198.51.100.201").getSnmpInterface().getIfIndex().intValue());
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.204").getIfIndex().intValue());
    assertEquals(5, getInterfaceDao().get(node, "198.51.100.204").getSnmpInterface().getIfIndex().intValue());
}
Also used : SnmpAgentAddress(org.opennms.netmgt.snmp.SnmpAgentAddress) OnmsNode(org.opennms.netmgt.model.OnmsNode) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 18 with JUnitSnmpAgent

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

the class SnmpCollectorWithMibPropertiesIT method testCollect.

/**
     * Test collection with MibObj Properties.
     *
     * @throws Exception the exception
     */
@Test
@JUnitCollector(datacollectionType = "snmp", datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config-NMS8484.xml")
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/airespace.properties")
public void testCollect() throws Exception {
    System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    Map<String, String> slot0 = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "bsnAPIfLoadParametersEntry", "132.178.97.20.31.224.0"));
    assertEquals("AP84b2.6111.29ac", slot0.get("bsnAPName"));
    assertEquals("0", slot0.get("slotNumber"));
    Map<String, String> slot1 = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "bsnAPIfLoadParametersEntry", "132.178.97.20.31.224.1"));
    assertEquals("AP84b2.6111.29ac", slot1.get("bsnAPName"));
    assertEquals("1", slot1.get("slotNumber"));
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 19 with JUnitSnmpAgent

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

the class SnmpCollectorWithMibPropertiesIT method testCollectCiscoQoS.

/**
     * Test collection for Cisco QoS with MibObj Properties.
     *
     * @throws Exception the exception
     */
@Test
@JUnitCollector(datacollectionType = "snmp", datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config-cisco-qos.xml")
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/cisco-qos.properties")
public void testCollectCiscoQoS() throws Exception {
    System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    Map<String, String> map = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "cbQosCMStatsEntry", "290.508801"));
    assertEquals("OUTBOUND-LLQ", map.get("cbQosClassMapPolicy"));
    assertEquals("GESTION-ROUTING", map.get("cbQosClassMapName"));
    assertEquals("Conexion Valencia", map.get("ifAlias"));
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 20 with JUnitSnmpAgent

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

the class SnmpCollectorIT method verifyPersistedStringProperties.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void verifyPersistedStringProperties() throws Exception {
    // Perform the collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    // Persist
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    // Verify results on disk
    Map<String, String> properties = m_resourceStorageDao.getStringAttributes(ResourcePath.get("snmp", "1", "brocadeFCPortIndex", "1"));
    // "string" attributes should convert the octets directly to a string
    String value = properties.get("swFCPortName");
    assertTrue(value.startsWith("..3DUfw"));
    // "hexstring" attributes should convert the octets to a hex string
    // see http://issues.opennms.org/browse/NMS-7367
    value = properties.get("swFCPortWwn");
    assertEquals("1100334455667788", value);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)21 Test (org.junit.Test)19 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)8 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)4 Transactional (org.springframework.transaction.annotation.Transactional)4 File (java.io.File)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 SnmpAgentAddress (org.opennms.netmgt.snmp.SnmpAgentAddress)2 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignore (org.junit.Ignore)1 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)1 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)1 LldpLink (org.opennms.netmgt.model.LldpLink)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1