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));
}
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;
}
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));
}
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));
}
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));
}
Aggregations