Search in sources :

Example 16 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue 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 17 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue 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 18 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue 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 19 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue 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 20 with SnmpValue

use of org.opennms.netmgt.snmp.SnmpValue 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

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)14 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4