use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testSendWithGetPduMultipleValues.
@Test
public void testSendWithGetPduMultipleValues() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.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", 2, values.length);
assertSnmpValueEquals("values[0]", SnmpValue.SNMP_INT32, 42, values[0]);
assertSnmpValueEquals("values[0]", SnmpValue.SNMP_GAUGE32, 42, values[1]);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testSendWithGetNextPduMultipleValues.
@Test
public void testSendWithGetNextPduMultipleValues() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0"), SnmpObjId.get(".1.3.5.1.1.4.0") };
Snmp4JAgentConfig agentConfig = new Snmp4JAgentConfig(getAgentConfig());
SnmpValue[] retvalues = null;
/*
* Build the PDU first, since there isn't any value in doing other
* work like setting up the session if we don't have anything to send.
*/
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", 2, values.length);
// Expect the *next* value, so for .1.3.5.1.1.4.0
assertSnmpValueEquals("values[0]", SnmpValue.SNMP_GAUGE32, 42, values[0]);
// Expect the *next* value, so for .1.3.5.1.1.5.0
assertSnmpValueEquals("values[1]", SnmpValue.SNMP_COUNTER32, 42, values[1]);
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class Snmp4JStrategyIT method testSendWithNullConfig.
@Test
@Ignore
public void testSendWithNullConfig() throws Exception {
SnmpObjId[] oids = new SnmpObjId[] { SnmpObjId.get(".1.3.5.1.1.3.0") };
SnmpValue[] retvalues = null;
PDU pdu = m_strategy.buildPdu(null, PDU.GET, oids, null);
if (pdu != null) {
retvalues = m_strategy.send(null, 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 Snmp4jTrapReceiverIT method sendTraps.
private void sendTraps(final Snmp4JStrategy strategy, final int v3Level) throws Exception {
final String hostAddress = str(getAgentAddress());
LOG.debug("Sending V2 Trap");
SnmpObjId enterpriseId = SnmpObjId.get(".0.0");
SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
SnmpTrapBuilder pdu = strategy.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
pdu.send(hostAddress, 9162, "public");
LOG.debug("Sending V3 Trap");
SnmpV3TrapBuilder pduv3 = strategy.getV3TrapBuilder();
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
switch(v3Level) {
case SnmpConfiguration.NOAUTH_NOPRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.NOAUTH_NOPRIV, "noAuthUser", null, null, null, null);
break;
case SnmpConfiguration.AUTH_PRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.AUTH_PRIV, "opennmsUser", "0p3nNMSv3", SnmpConfiguration.DEFAULT_AUTH_PROTOCOL, "0p3nNMSv3", SnmpConfiguration.DEFAULT_PRIV_PROTOCOL);
break;
default:
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class TestAgentTest method testLoadSnmpData.
public void testLoadSnmpData() throws Exception {
TestAgent agent = new TestAgent();
agent.loadSnmpTestData(getClass(), "/loadSnmpDataTest.properties");
SnmpObjId z1 = SnmpObjId.get(zeroInst1Base, "0");
assertEquals("TestData", agent.getValueFor(z1).toString());
}
Aggregations