Search in sources :

Example 6 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TestAgent method getNextResponseVarBind.

TestVarBind getNextResponseVarBind(SnmpObjId lastOid, int errIndex) {
    try {
        SnmpObjId objId = getFollowingObjId(lastOid);
        SnmpValue value = getVarBindValue(objId, errIndex);
        return new TestVarBind(objId, value);
    } catch (AgentEndOfMibException e) {
        return handleEndOfMib(lastOid, errIndex);
    }
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 7 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TestAgent method getFollowingObjId.

public SnmpObjId getFollowingObjId(SnmpObjId id) {
    try {
        SnmpObjId nextObjId = m_agentData.tailMap(SnmpObjId.get(id, SnmpInstId.INST_ZERO)).firstKey();
        Object value = m_agentData.get(nextObjId);
        if (value instanceof Redirect) {
            Redirect redirect = (Redirect) value;
            return redirect.getTargetObjId();
        }
        return nextObjId;
    } catch (NoSuchElementException e) {
        throw new AgentEndOfMibException();
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TestAgent method generateException.

private void generateException(SnmpObjId id) {
    if (m_agentData.isEmpty()) {
        throw new AgentNoSuchObjectException();
    }
    SnmpObjId firstOid = m_agentData.firstKey();
    SnmpObjId lastOid = m_agentData.lastKey();
    if (id.compareTo(firstOid) < 0 || id.compareTo(lastOid) > 0)
        throw new AgentNoSuchObjectException();
    throw new AgentNoSuchInstanceException();
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 9 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TestAgent method setAgentData.

public void setAgentData(Properties mibData) {
    MockSnmpValueFactory factory = new MockSnmpValueFactory();
    m_agentData = new TreeMap<SnmpObjId, Object>();
    for (Entry<Object, Object> entry : mibData.entrySet()) {
        SnmpObjId objId = SnmpObjId.get(entry.getKey().toString());
        setAgentValue(objId, factory.parseMibValue(entry.getValue().toString()));
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 10 with SnmpObjId

use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.

the class TestAgentTest method testAgentValueFor.

public void testAgentValueFor() {
    SnmpObjId z1 = SnmpObjId.get(zeroInst1Base, "0");
    SnmpObjId z2 = SnmpObjId.get(zeroInst2Base, "0");
    assertEquals(getValueFor(z1).toString(), m_agent.getValueFor(z1).toString());
    assertEquals(getValueFor(z2).toString(), m_agent.getValueFor(z2).toString());
    // make sure they are not the same
    assertFalse(getValueFor(z2).equals(m_agent.getValueFor(z1)));
    // try a column
    for (int i = 1; i <= columnLength; i++) {
        SnmpObjId colOid = SnmpObjId.get(col2Base, "" + i);
        assertEquals(getValueFor(colOid).toString(), m_agent.getValueFor(colOid).toString());
    }
    // what should it do if you ask for an invalid one - return null
    try {
        m_agent.getValueFor(SnmpObjId.get(".1.1.1.1.1"));
        fail("expected an exception");
    } catch (AgentNoSuchObjectException e) {
    }
    SnmpObjId objId = SnmpObjId.get(zeroInst1Base, "1");
    try {
        m_agent.getValueFor(objId);
        fail("Expected no such instance exception");
    } catch (AgentNoSuchInstanceException e) {
    }
    RuntimeException exception = m_agent.introduceGenErr(objId);
    try {
        m_agent.getValueFor(objId);
    } catch (RuntimeException e) {
        assertSame(exception, e);
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

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