Search in sources :

Example 1 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class TableTrackerProxyTest method canHandleAValidResponse.

@Test
public void canHandleAValidResponse() {
    // Build a response with an OID from the requested table
    SnmpValue value = mock(SnmpValue.class);
    SnmpResult result = new SnmpResult(table, SnmpInstId.INST_ZERO, value);
    WalkResponse response = new WalkResponse(Collections.singletonList(result));
    // Resolve the walker
    tracker.handleWalkResponses(Collections.singletonList(response));
    // We should be finished, and have captured the expected value
    assertThat(tracker.isFinished(), equalTo(true));
    assertThat(rows, hasSize(1));
    assertThat(rows.get(0).getValue(table), equalTo(value));
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 2 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class JoeSnmpStrategy method getNext.

@Override
public SnmpValue[] getNext(SnmpAgentConfig snmpAgentConfig, SnmpObjId[] oids) {
    JoeSnmpAgentConfig agentConfig = new JoeSnmpAgentConfig(snmpAgentConfig);
    SnmpSession session = null;
    SnmpValue[] values = { null };
    try {
        SnmpPeer peer = createPeer(agentConfig);
        SnmpParameters params = new SnmpParameters();
        setParameters(agentConfig, params);
        peer.setParameters(params);
        configurePeer(peer, agentConfig);
        session = new SnmpSession(peer);
        SnmpObjectId[] jOids = convertOids(oids);
        SnmpSyntax[] results = session.getNext(jOids);
        values = convertSnmpSyntaxs(results);
    } catch (SocketException e) {
        LOG.error("Could not create JoeSNMP session using AgentConfig: {}", agentConfig);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return values;
}
Also used : SnmpSyntax(org.opennms.protocols.snmp.SnmpSyntax) SocketException(java.net.SocketException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpObjectId(org.opennms.protocols.snmp.SnmpObjectId) SnmpSession(org.opennms.protocols.snmp.SnmpSession) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Example 3 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class AggregateTrackerProxyTest method canHandleValidResponses.

@Test
public void canHandleValidResponses() {
    // Build responses
    SnmpValue value = mock(SnmpValue.class);
    List<WalkResponse> responses = Lists.newArrayList(new WalkResponse(Collections.singletonList(new SnmpResult(baseOids[0], SnmpInstId.INST_ZERO, value)), "0-0"), new WalkResponse(Collections.singletonList(new SnmpResult(baseOids[1], SnmpInstId.INST_ZERO, value)), "0-1"), new WalkResponse(Collections.singletonList(new SnmpResult(baseOids[2], SnmpInstId.INST_ZERO, value)), "0-2"), new WalkResponse(Collections.singletonList(new SnmpResult(baseOids[3], SnmpInstId.INST_ZERO, value)), "1"));
    // Resolve the walker
    parentAggregateTracker.handleWalkResponses(responses);
    // We should be finished, and have captured the expected results
    assertThat(parentAggregateTracker.isFinished(), equalTo(true));
    assertThat(gatherer.getResults(), hasSize(4));
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 4 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class ColumnTrackerProxyTest method canHandleValidResponses.

@Test
public void canHandleValidResponses() {
    // Build a response with the requested OID
    SnmpValue value = mock(SnmpValue.class);
    List<SnmpResult> results = new ArrayList<>();
    results.add(new SnmpResult(base, SnmpInstId.INST_ZERO, value));
    // Outside of base
    results.add(new SnmpResult(SnmpObjId.get(".1.3.6.1.2.2"), SnmpInstId.INST_ZERO, null));
    WalkResponse response = new WalkResponse(results);
    // Resolve the walker
    tracker.handleWalkResponses(Collections.singletonList(response));
    // We should be finished, and have captured the expected value
    assertThat(tracker.isFinished(), equalTo(true));
    assertThat(gatherer.getResults(), hasSize(1));
    assertThat(gatherer.getResults().get(0).getValue(), equalTo(value));
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) ArrayList(java.util.ArrayList) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Example 5 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue in project opennms by OpenNMS.

the class SingleInstanceTrackerProxyTest method canHandleResponsesForOtherOids.

@Test
public void canHandleResponsesForOtherOids() {
    // Build a response for another OID
    SnmpValue value = mock(SnmpValue.class);
    SnmpResult result = new SnmpResult(SnmpObjId.get(".1.3.6.1.2.1.1.1"), instance, value);
    WalkResponse response = new WalkResponse(Collections.singletonList(result));
    // Resolve the walker
    tracker.handleWalkResponses(Collections.singletonList(response));
    // We should be finished, without any captured values
    assertThat(tracker.isFinished(), equalTo(true));
    assertThat(gatherer.getResults(), hasSize(0));
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) Test(org.junit.Test)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)14 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4