use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class V1TrapInformation method getSnmpVarBindDTO.
@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
return new SnmpVarBindDTO(name, value);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class V2TrapInformation method getSnmpVarBindDTO.
@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
if (i < 2) {
if (i == 0) {
LOG.debug("Skipping processing of varbind it is the sysuptime and the first varbind, it is not processed as a parm per RFC2089");
} else {
LOG.debug("Skipping processing of varbind it is the trap OID and the second varbind, it is not processed as a parm per RFC2089");
}
return null;
} else {
SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
return new SnmpVarBindDTO(name, value);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class RequestPdu method send.
/*
* This simulates send a packet and waiting for a response.
*
* This is a template method based on te getBulk algorithm. We use the getBulk
* algorithm for get and nexts as well. nonRepeaters for gets and nexts is always
* equals to pdu size so there are no repeaters. maxRepitions is also always zero
* for gets and nexts.
*
* The method getRespObjIdFromReqObjId which by default goes 'next' is overridden
* and does 'get' in the GetPdu.
*/
public ResponsePdu send(TestAgent agent) {
ResponsePdu resp = TestPdu.getResponse();
try {
// first do non repeaters
int nonRepeaters = Math.min(size(), getNonRepeaters());
for (int i = 0; i < nonRepeaters; i++) {
int errIndex = i + 1;
TestVarBind varBind = (TestVarBind) getVarBindAt(i);
SnmpObjId lastOid = varBind.getObjId();
TestVarBind newVarBind = getResponseVarBind(agent, lastOid, errIndex);
resp.addVarBind(newVarBind);
// make sure we haven't exceeded response size
validateResponseSize(resp, agent);
}
// make a list to track the repititions
int repeaters = size() - nonRepeaters;
List<SnmpObjId> repeaterList = new ArrayList<SnmpObjId>(repeaters);
for (int i = nonRepeaters; i < size(); i++) {
repeaterList.add(getVarBindAt(i).getObjId());
}
// now generate varbinds for the repeaters
for (int count = 0; count < getMaxRepititions(); count++) {
for (int i = 0; i < repeaterList.size(); i++) {
int errIndex = nonRepeaters + i + 1;
SnmpObjId lastOid = (SnmpObjId) repeaterList.get(i);
TestVarBind newVarBind = getResponseVarBind(agent, lastOid, errIndex);
resp.addVarBind(newVarBind);
repeaterList.set(i, newVarBind.getObjId());
// make sure we haven't exceeded response size
validateResponseSize(resp, agent);
}
}
return resp;
} catch (AgentIndexException e) {
// this happens for GenErr and NoSuchName errs
resp.setVarBinds(getVarBinds());
resp.setErrorStatus(e.getErrorStatus());
// errorIndex uses indices starting at 1
resp.setErrorIndex(e.getErrorIndex());
return resp;
} catch (AgentTooBigException e) {
// when we exceed response size we'll get here
return handleTooBig(agent, resp);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class MockSnmpStrategyTest method testSetMultipleBadAgent.
@Test
public void testSetMultipleBadAgent() throws Exception {
final SnmpAgentConfig sac = getAgentConfig();
sac.setAddress(InetAddressUtils.addr("1.2.3.4"));
final SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
final SnmpValue[] values = new SnmpValue[] { m_strategy.getValueFactory().getInt32(4), m_strategy.getValueFactory().getGauge32(5) };
m_strategy.set(sac, oids, values);
final SnmpValue[] results = m_strategy.get(sac, oids);
assertNotNull(results);
assertEquals(2, results.length);
assertNull(results[0]);
assertNull(results[1]);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class SnmpProxyRpcModule method walk.
private CompletableFuture<Collection<SnmpResponseDTO>> walk(SnmpRequestDTO request, List<SnmpWalkRequestDTO> walks) {
final CompletableFuture<Collection<SnmpResponseDTO>> future = new CompletableFuture<>();
final Map<String, SnmpResponseDTO> responsesByCorrelationId = new LinkedHashMap<>();
final List<Collectable> trackers = new ArrayList<>(walks.size());
for (final SnmpWalkRequestDTO walk : walks) {
CollectionTracker tracker;
if (walk.getInstance() != null) {
if (walk.getOids().size() != 1) {
future.completeExceptionally(new IllegalArgumentException("Single instance requests must have a single OID."));
return future;
}
final SnmpObjId oid = walk.getOids().get(0);
tracker = new SingleInstanceTracker(oid, new SnmpInstId(walk.getInstance())) {
@Override
protected void storeResult(SnmpResult res) {
addResult(res, walk.getCorrelationId(), responsesByCorrelationId);
}
};
} else {
final Collection<Collectable> columnTrackers = walk.getOids().stream().map(oid -> SnmpObjId.get(oid)).map(objId -> new ColumnTracker(objId)).collect(Collectors.toList());
tracker = new AggregateTracker(columnTrackers) {
@Override
protected void storeResult(SnmpResult res) {
addResult(res, walk.getCorrelationId(), responsesByCorrelationId);
}
};
}
if (walk.getMaxRepetitions() != null) {
tracker.setMaxRepetitions(walk.getMaxRepetitions());
}
trackers.add(tracker);
}
AggregateTracker aggregate = new AggregateTracker(trackers);
final SnmpWalker walker = SnmpUtils.createWalker(request.getAgent(), request.getDescription(), aggregate);
walker.setCallback(new SnmpWalkCallback() {
@Override
public void complete(SnmpWalker tracker, Throwable t) {
try {
if (t != null) {
future.completeExceptionally(t);
} else {
future.complete(responsesByCorrelationId.values());
}
} finally {
// Close the tracker using a separate thread
// This allows the SnmpWalker to clean up properly instead
// of interrupting execution as it's executing the callback
REAPER_EXECUTOR.submit(new Runnable() {
@Override
public void run() {
tracker.close();
}
});
}
}
});
walker.start();
return future;
}
Aggregations