Search in sources :

Example 11 with OnmsAccessPoint

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

the class InstanceStrategyIntegrationTest method testDynamicPackageConfig.

/*
     * Test the behaviour when packages are not explicitely defined in the
     * configuration file (i.e. dynamic packages) Verify: That the proper
     * events are sent by the daemon.
     */
@Test
@JUnitSnmpAgent(host = "10.1.0.2", resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt")
public void testDynamicPackageConfig() throws Exception {
    // Add AP1 to a new package
    addNewAccessPoint("ap1", AP1_MAC, "aruba-default-pkg");
    // Add the controller in the same package
    addNewController("amc1", "10.1.0.2", "aruba-default-pkg");
    // Set the access point state
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 1);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    // Initialize and start the daemon
    initApmdWithConfig(getDynamicPackageConfig());
    m_apm.start();
    // The AP should be reported as UP even though the package is not
    // explicitly defined
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Delete AP1
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    m_accessPointDao.delete(ap1);
    m_accessPointDao.flush();
    // Wait for the package scan to kick in
    sleep(2000);
    // Take the AP off-line
    anticipateApStatusEvent(AP1_MAC, "DOWN");
    // No event should be generated
    sleep(POLLING_INTERVAL_DELTA);
    assertEquals("Received unexpected events", 0, m_anticipator.getUnanticipatedEvents().size());
    m_anticipator.reset();
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 12 with OnmsAccessPoint

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

the class InstanceStrategy method call.

@Override
public OnmsAccessPointCollection call() throws IOException {
    OnmsAccessPointCollection apsUp = new OnmsAccessPointCollection();
    InetAddress ipaddr = m_iface.getIpAddress();
    // Retrieve this interface's SNMP peer object
    SnmpAgentConfig agentConfig = getAgentConfig(ipaddr);
    final String hostAddress = InetAddressUtils.str(ipaddr);
    LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
    // Get configuration parameters
    String oid = ParameterMap.getKeyedString(m_parameters, "oid", null);
    if (oid == null) {
        throw new IllegalStateException("oid parameter is not set.");
    }
    String operator = ParameterMap.getKeyedString(m_parameters, "operator", null);
    String operand = ParameterMap.getKeyedString(m_parameters, "operand", null);
    String matchstr = ParameterMap.getKeyedString(m_parameters, "match", "true");
    LOG.debug("InstanceStrategy.poll: SnmpAgentConfig address= {}", agentConfig);
    // Establish SNMP session with interface
    try {
        SnmpObjId snmpObjectId = SnmpObjId.get(oid);
        Map<SnmpInstId, SnmpValue> map = SnmpUtils.getOidValues(agentConfig, "AccessPointMonitor::InstanceStrategy", snmpObjectId);
        if (map.size() <= 0) {
            throw new IOException("No entries found in table (possible timeout).");
        }
        for (Map.Entry<SnmpInstId, SnmpValue> entry : map.entrySet()) {
            boolean isUp = false;
            SnmpInstId instance = entry.getKey();
            SnmpValue value = entry.getValue();
            // Check the value against the configured criteria
            if (meetsCriteria(value, operator, operand)) {
                if ("true".equals(matchstr)) {
                    isUp = true;
                }
            } else if ("false".equals(matchstr)) {
                isUp = true;
            }
            // of online APs
            if (isUp) {
                String physAddr = getPhysAddrFromInstance(instance);
                LOG.debug("AP at instance '{}' with MAC '{}' is considered to be ONLINE on controller '{}'", instance, physAddr, m_iface.getIpAddress());
                OnmsAccessPoint ap = m_accessPointDao.get(physAddr);
                if (ap != null) {
                    if (ap.getPollingPackage().compareToIgnoreCase(getPackage().getName()) == 0) {
                        // Save the controller's IP address
                        ap.setControllerIpAddress(ipaddr);
                        apsUp.add(ap);
                    } else {
                        LOG.info("AP with MAC '{}' is in a different package.", physAddr);
                    }
                } else {
                    LOG.info("No matching AP in database for instance '{}'.", instance);
                }
            }
        }
    } catch (NumberFormatException e) {
        LOG.error("Number operator used on a non-number ", e);
    } catch (IllegalArgumentException e) {
        LOG.error("Invalid SNMP Criteria ", e);
    } catch (InterruptedException e) {
        LOG.error("Interrupted while polling {}", hostAddress, e);
    }
    return apsUp;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OnmsAccessPointCollection(org.opennms.netmgt.model.OnmsAccessPointCollection) IOException(java.io.IOException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) InetAddress(java.net.InetAddress) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Example 13 with OnmsAccessPoint

use of org.opennms.netmgt.model.OnmsAccessPoint 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 14 with OnmsAccessPoint

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

the class InstanceStrategyIntegrationTest method testManyControllers.

/*
     * Test the behaviour when multiple controllers are configured in a single
     * package. Verify: That the proper events are sent by the daemon. The AP
     * state and the controller's address in the database after the poll.
     */
@Test
@JUnitSnmpAgents(value = { @JUnitSnmpAgent(host = "10.1.0.2", port = 161, resource = SNMP_DATA_PATH + "10.1.0.2-walk.txt"), @JUnitSnmpAgent(host = "10.1.1.2", port = 161, resource = SNMP_DATA_PATH + "10.1.1.2-walk.txt"), @JUnitSnmpAgent(host = "10.1.2.2", port = 161, resource = SNMP_DATA_PATH + "10.1.2.2-walk.txt") })
public void testManyControllers() throws Exception {
    // Add AP1 and AP2 to the default package
    addNewAccessPoint("ap1", AP1_MAC, "default");
    addNewAccessPoint("ap2", AP2_MAC, "default");
    // Add AP3 to a separate package
    addNewAccessPoint("ap3", AP3_MAC, "not-default");
    // Add 3 controllers to the default package
    addNewController("amc0", "10.1.0.2", "default");
    addNewController("amc1", "10.1.1.2", "default");
    addNewController("amc2", "10.1.2.2", "default");
    // Set the access point state on all 3 controllers
    setOidValueForAccessPoint("10.1.0.2", AP1_MAC, 0);
    setOidValueForAccessPoint("10.1.0.2", AP2_MAC, 0);
    setOidValueForAccessPoint("10.1.1.2", AP1_MAC, 1);
    setOidValueForAccessPoint("10.1.1.2", AP2_MAC, 0);
    setOidValueForAccessPoint("10.1.2.2", AP1_MAC, 0);
    setOidValueForAccessPoint("10.1.2.2", AP2_MAC, 1);
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "UP");
    // Initialize and start the daemon
    initApmdWithConfig(getMultiControllerConfig());
    m_apm.start();
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    assertEquals(InetAddressUtils.getInetAddress("10.1.1.2"), ap1.getControllerIpAddress());
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.ONLINE);
    assertEquals(InetAddressUtils.getInetAddress("10.1.2.2"), ap2.getControllerIpAddress());
    // Anticipate the events
    anticipateApStatusEvent(AP1_MAC, "UP");
    anticipateApStatusEvent(AP2_MAC, "UP");
    // Move AP1 to amc2
    setOidValueForAccessPoint("10.1.1.2", AP1_MAC, 0);
    setOidValueForAccessPoint("10.1.2.2", AP1_MAC, 1);
    // Move AP2 to amc1
    setOidValueForAccessPoint("10.1.1.2", AP2_MAC, 1);
    setOidValueForAccessPoint("10.1.2.2", AP2_MAC, 0);
    // Verify the events
    verifyAnticipated(POLLING_INTERVAL_DELTA);
    // Verify the controller address in the database
    ap1 = m_accessPointDao.get(AP1_MAC);
    assertTrue(ap1.getStatus() == AccessPointStatus.ONLINE);
    assertEquals(InetAddressUtils.getInetAddress("10.1.2.2"), ap1.getControllerIpAddress());
    ap2 = m_accessPointDao.get(AP2_MAC);
    assertTrue(ap2.getStatus() == AccessPointStatus.ONLINE);
    assertEquals(InetAddressUtils.getInetAddress("10.1.1.2"), ap2.getControllerIpAddress());
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) JUnitSnmpAgents(org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)

Aggregations

OnmsAccessPoint (org.opennms.netmgt.model.OnmsAccessPoint)14 Test (org.junit.Test)7 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)4 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)3 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Map (java.util.Map)2 ParameterMap (org.opennms.core.utils.ParameterMap)2 OnmsAccessPointCollection (org.opennms.netmgt.model.OnmsAccessPointCollection)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)2 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)2 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)1 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Event (org.opennms.netmgt.xml.event.Event)1