Search in sources :

Example 11 with SnmpObjId

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());
    }
}
Also used : PDU(org.snmp4j.PDU) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) VariableBinding(org.snmp4j.smi.VariableBinding) Test(org.junit.Test)

Example 12 with SnmpObjId

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);
    }
}
Also used : PDU(org.snmp4j.PDU) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) VariableBinding(org.snmp4j.smi.VariableBinding) Test(org.junit.Test)

Example 13 with SnmpObjId

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();
}
Also used : PDU(org.snmp4j.PDU) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Example 14 with SnmpObjId

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]);
}
Also used : PDU(org.snmp4j.PDU) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Example 15 with SnmpObjId

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]);
}
Also used : PDU(org.snmp4j.PDU) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)71 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)48 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)22 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)20 InetAddress (java.net.InetAddress)18 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 Test (org.junit.Test)13 PollStatus (org.opennms.netmgt.poller.PollStatus)12 PDU (org.snmp4j.PDU)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)7 List (java.util.List)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 ExecutionException (java.util.concurrent.ExecutionException)4 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)4 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3