use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class MapSubAgent method getNext.
@Override
public VariableBinding getNext(OID requested) {
OID successor = nextOID(requested);
SortedMap<OID, Variable> tailMap = m_values.tailMap(successor);
if (tailMap.isEmpty()) {
return null;
}
OID next = tailMap.firstKey();
Variable value = tailMap.get(next);
return new VariableBinding(next, value);
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class MockSnmpAgentIT method requestAndVerifyResponse.
private void requestAndVerifyResponse(int pduType, int version) throws Exception {
PDU pdu = createPDU(version);
for (AnticipatedRequest a : m_requestedVarbinds) {
pdu.add(a.getRequestVarbind());
}
pdu.setType(pduType);
PDU response = sendRequest(pdu, version);
assertNotNull("request timed out", response);
System.err.println("Response is: " + response);
assertTrue("unexpected report pdu: " + ((VariableBinding) response.getVariableBindings().get(0)).getOid(), response.getType() != PDU.REPORT);
assertEquals("Unexpected number of varbinds returned.", m_requestedVarbinds.size(), response.getVariableBindings().size());
for (int i = 0; i < m_requestedVarbinds.size(); i++) {
AnticipatedRequest a = m_requestedVarbinds.get(i);
VariableBinding vb = response.get(i);
a.verify(vb);
}
reset();
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class LLDPMibIT method requestAndVerifyResponse.
private void requestAndVerifyResponse(int pduType, int version) throws Exception {
PDU pdu = createPDU(version);
for (AnticipatedRequest a : m_requestedVarbinds) {
pdu.add(a.getRequestVarbind());
}
pdu.setType(pduType);
PDU response = sendRequest(pdu, version);
assertNotNull("request timed out", response);
System.err.println("Response is: " + response);
assertTrue("unexpected report pdu: " + ((VariableBinding) response.getVariableBindings().get(0)).getOid(), response.getType() != PDU.REPORT);
assertEquals("Unexpected number of varbinds returned.", m_requestedVarbinds.size(), response.getVariableBindings().size());
for (int i = 0; i < m_requestedVarbinds.size(); i++) {
AnticipatedRequest a = m_requestedVarbinds.get(i);
VariableBinding vb = response.get(i);
a.verify(vb);
}
reset();
}
use of org.snmp4j.smi.VariableBinding in project Payara by payara.
the class SnmpNotificationRunnable method run.
@Override
public void run() {
while (queue.size() > 0) {
try {
PDU pdu = DefaultPDUFactory.createPDU(snmpVersion);
if (SnmpConstants.version1 == snmpVersion) {
pdu.setType(PDU.V1TRAP);
} else {
pdu.setType(PDU.TRAP);
}
pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
OID oidInstance = new OID(executionOptions.getOid());
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, oidInstance));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(executionOptions.getHost())));
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(new Date().toString())));
SnmpMessage message = queue.getMessage();
pdu.add(new VariableBinding(oidInstance, new OctetString(message.getSubject() + "\n" + message.getMessage())));
snmp.send(pdu, communityTarget);
logger.log(Level.FINE, "Message sent successfully");
} catch (IOException e) {
logger.log(Level.SEVERE, "IO Error while sending SNMP message", e);
}
}
}
use of org.snmp4j.smi.VariableBinding in project camel by apache.
the class SnmpOIDPoller method poll.
@Override
protected int poll() throws Exception {
this.pdu.clear();
int type = this.getPduType(this.endpoint.getType());
this.pdu.setType(type);
// prepare the request items
for (OID oid : this.endpoint.getOids()) {
this.pdu.add(new VariableBinding(oid));
}
// send the request
snmp.send(pdu, target, null, this);
return 1;
}
Aggregations