use of org.snmp4j.smi.VariableBinding in project openhab1-addons by openhab.
the class SnmpBinding method internalReceiveCommand.
/**
* @{inheritDoc
*/
@Override
public void internalReceiveCommand(String itemName, Command command) {
logger.debug("SNMP receive command {} from {}", itemName, command);
SnmpBindingProvider providerCmd = null;
for (SnmpBindingProvider provider : this.providers) {
OID oid = provider.getOID(itemName, command);
if (oid != null) {
providerCmd = provider;
break;
}
}
if (providerCmd == null) {
logger.warn("No match for binding provider [itemName={}, command={}]", itemName, command);
return;
}
logger.debug("SNMP command for {} to {}", itemName, providerCmd.toString());
// Set up the target
CommunityTarget target = new CommunityTarget();
target.setCommunity(providerCmd.getCommunity(itemName, command));
target.setAddress(providerCmd.getAddress(itemName, command));
target.setRetries(retries);
target.setTimeout(timeout);
target.setVersion(providerCmd.getSnmpVersion(itemName, command));
Variable var = providerCmd.getValue(itemName, command);
OID oid = providerCmd.getOID(itemName, command);
VariableBinding varBind = new VariableBinding(oid, var);
// Create the PDU
PDU pdu = new PDU();
pdu.add(varBind);
pdu.setType(PDU.SET);
pdu.setRequestID(new Integer32(1));
logger.debug("SNMP: Send CMD PDU {} {}", providerCmd.getAddress(itemName, command), pdu);
if (snmp == null) {
logger.error("SNMP: snmp not initialised - aborting request");
} else {
sendPDU(target, pdu);
}
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class PropertiesBackedManagedObject method getVariable.
private void getVariable(final SubRequest request, final OID oid) {
try {
final Variable value = findValueForOID(oid);
final VariableBinding vb = request.getVariableBinding();
vb.setOid(oid);
vb.setVariable(value == null ? Null.noSuchObject : value);
request.completed();
} catch (SnmpErrorStatusException e) {
request.setErrorStatus(e.getErrorStatus());
request.completed();
}
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class BrocadeMibIT 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 MockSnmpAgentIT method testSleeperResponder.
@Test
public void testSleeperResponder() throws Exception {
final String myOid = "1.3.5.1.1.11.0";
// Verify that the sleeper responds correctly
Sleeper.getInstance().setVariable(new Integer32(1));
request(myOid).andExpect(myOid, SMIConstants.SYNTAX_INTEGER, new Integer32(1));
doGet();
// Set the timeout
Sleeper.getInstance().setSleepTime(DEFAULT_TIMEOUT + 1000);
// Make another request
PDU pdu = createPDU(m_version);
OID oid = new OID(myOid);
pdu.add(new VariableBinding(oid));
pdu.setType(PDU.GET);
PDU response = sendRequest(pdu, m_version);
// Verify that the request does in fact timeout
assertNull("request timed out", response);
// Clear the timeout
Sleeper.getInstance().setSleepTime(0);
// Update the variable
Sleeper.getInstance().setVariable(new OctetString("Bingo!"));
request(myOid).andExpect(myOid, SMIConstants.SYNTAX_OCTET_STRING, new OctetString("Bingo!"));
doGet();
}
use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class TrapNotificationSerializationTest method testsnmp4JV3Serialization.
@Test
public void testsnmp4JV3Serialization() throws UnknownHostException {
// create instance of snmp4JV3Trap
PDU snmp4JV3TrapPdu = new ScopedPDU();
snmp4JV3TrapPdu.setType(PDU.TRAP);
snmp4JV3TrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("mockhost")));
snmp4JV3TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("mockhost")));
snmp4JV3TrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.0"), new OctetString("mockhost")));
TrapInformation snmp4JV3Trap = new Snmp4JTrapNotifier.Snmp4JV2TrapInformation(inetAddress, new String("public"), snmp4JV3TrapPdu);
assertTrue(writeTrapNotificationObject(snmp4JV3Trap));
}
Aggregations