Search in sources :

Example 61 with SnmpObjId

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

Example 62 with SnmpObjId

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

Example 63 with SnmpObjId

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

Example 64 with SnmpObjId

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:
    }
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OctetString(org.snmp4j.smi.OctetString) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 65 with SnmpObjId

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

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)73 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)47 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)23 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 InetAddress (java.net.InetAddress)19 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Map (java.util.Map)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 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)6 List (java.util.List)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3