Search in sources :

Example 71 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId 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)

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)71 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)48 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)22 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)20 InetAddress (java.net.InetAddress)18 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 Test (org.junit.Test)13 PollStatus (org.opennms.netmgt.poller.PollStatus)12 PDU (org.snmp4j.PDU)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)7 List (java.util.List)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 ExecutionException (java.util.concurrent.ExecutionException)4 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)4 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3