use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testPreparePduWithValues.
@Test
public void testPreparePduWithValues() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
SnmpValue[] values = new SnmpValue[] { snmpValue("foo"), snmpValue("bar") };
PDU pdu = m_strategy.buildPdu(new Snmp4JAgentConfig(getAgentConfig()), PDU.SET, oids, values);
assertNotNull("PDU should not be null", pdu);
assertEquals("PDU variable bindings size", oids.length, pdu.getVariableBindings().size());
for (int i = 0; i < oids.length; i++) {
VariableBinding vb = pdu.get(i);
assertEquals("PDU variable binding " + i + " OID", oids[i].toString(), "." + vb.getOid().toString());
assertEquals("PDU variable binding " + i + " syntax", vb.getSyntax(), SMIConstants.SYNTAX_OCTET_STRING);
assertEquals("PDU variable binding " + i + " variable syntax", vb.getVariable().getSyntax(), SMIConstants.SYNTAX_OCTET_STRING);
assertEquals("PDU variable binding " + i + " variable value", vb.getVariable().toString(), values[i].toString());
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testPreparePduWithNoValues.
@Test
public void testPreparePduWithNoValues() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
SnmpValue[] values = null;
PDU pdu = m_strategy.buildPdu(new Snmp4JAgentConfig(getAgentConfig()), PDU.SET, oids, values);
assertNotNull("PDU should not be null", pdu);
assertEquals("PDU variable bindings size", oids.length, pdu.getVariableBindings().size());
for (int i = 0; i < oids.length; i++) {
VariableBinding vb = pdu.get(i);
assertEquals("PDU variable binding " + i + " OID", oids[i].toString(), "." + vb.getOid().toString());
assertEquals("PDU variable binding " + i + " syntax", vb.getSyntax(), SMIConstants.SYNTAX_NULL);
assertEquals("PDU variable binding " + i + " variable syntax", vb.getVariable().getSyntax(), SMIConstants.SYNTAX_NULL);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testPreparePduWithTooManyValues.
@Test
public void testPreparePduWithTooManyValues() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
SnmpValue[] values = new SnmpValue[] { snmpValue("foo"), snmpValue("bar"), snmpValue("baz") };
PDU pdu = m_strategy.buildPdu(new Snmp4JAgentConfig(getAgentConfig()), PDU.SET, oids, values);
assertNull("PDU should be null", pdu);
MockLogAppender.resetEvents();
MockLogAppender.resetLogLevel();
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testSendWithGetPduSingleValue.
@Test
public void testSendWithGetPduSingleValue() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0") };
Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(getAgentConfig());
SnmpValue[] retvalues = null;
PDU pdu = m_strategy.buildPdu(agentConfig, PDU.GET, oids, null);
if (pdu != null) {
retvalues = m_strategy.send(agentConfig, pdu, true);
}
SnmpValue[] values = retvalues;
assertNotNull("values should not be null", values);
assertEquals("values list size", 1, values.length);
assertSnmpValueEquals("values[0]", SnmpValue.SNMP_INT32, 42, values[0]);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testSendWithGetNextPduSingleValue.
@Test
public void testSendWithGetNextPduSingleValue() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0") };
Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(getAgentConfig());
SnmpValue[] retvalues = null;
PDU pdu = m_strategy.buildPdu(agentConfig, PDU.GETNEXT, oids, null);
if (pdu != null) {
retvalues = m_strategy.send(agentConfig, pdu, true);
}
SnmpValue[] values = retvalues;
assertNotNull("values should not be null", values);
assertEquals("values list size", 1, values.length);
// Expect the *next* value, so for .1.3.5.1.1.4.0
assertSnmpValueEquals("values[0]", SnmpValue.SNMP_GAUGE32, 42, values[0]);
}
Aggregations