Search in sources :

Example 66 with SnmpObjId

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

the class TestAgentTest method testEmptyAgent.

public void testEmptyAgent() {
    TestAgent agent = new TestAgent();
    SnmpObjId z1 = SnmpObjId.get(zeroInst1Base, "0");
    try {
        agent.getValueFor(z1);
        fail("Expected exception");
    } catch (AgentNoSuchObjectException e) {
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 67 with SnmpObjId

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

the class TestAgentTest method verifyNextVarBind.

private SnmpObjId verifyNextVarBind(SnmpObjId reqObjId, TestVarBind respVarBind) {
    try {
        SnmpObjId nextOid = m_agent.getFollowingObjId(reqObjId);
        assertEquals(nextOid, respVarBind.getObjId());
        verifyObjIdValue(respVarBind);
        return nextOid;
    } catch (AgentEndOfMibException e) {
        assertEquals(reqObjId, respVarBind.getObjId());
        assertEquals(MockSnmpValue.END_OF_MIB, respVarBind.getValue());
        return reqObjId;
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 68 with SnmpObjId

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

the class TestAgentTest method validateBulkResponse.

private void validateBulkResponse(BulkPdu pdu, ResponsePdu resp) {
    assertNotNull(resp);
    assertEquals(ErrorStatus.NO_ERROR.ordinal(), resp.getErrorStatus());
    int nonRepeaters = pdu.getNonRepeaters();
    int repeaters = (pdu.size() - nonRepeaters);
    // validate the length
    int expectedSize = Math.min(nonRepeaters + (repeaters * pdu.getMaxRepititions()), m_agent.getMaxResponseSize());
    assertEquals(expectedSize, resp.size());
    // validate the nonRepeaters
    for (int i = 0; i < nonRepeaters; i++) {
        verifyBulkVarBind(pdu.getVarBindAt(i).getObjId(), resp, i);
    }
    // validate the repeaters
    for (int i = 0; i < repeaters; i++) {
        SnmpObjId oid = pdu.getVarBindAt(i + nonRepeaters).getObjId();
        for (int count = 0; count < pdu.getMaxRepititions(); count++) {
            oid = verifyBulkVarBind(oid, resp, nonRepeaters + (count * repeaters) + i);
        }
    }
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 69 with SnmpObjId

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

the class TestAgentTest method testFollowingOid.

public void testFollowingOid() {
    SnmpObjId z1 = SnmpObjId.get(zeroInst1Base);
    SnmpObjId z2 = SnmpObjId.get(zeroInst2Base);
    SnmpObjId z1dot0 = SnmpObjId.get(z1, "0");
    SnmpObjId z2dot0 = SnmpObjId.get(z2, "0");
    SnmpObjId col1 = SnmpObjId.get(col1Base);
    SnmpObjId col1dot1 = SnmpObjId.get(col1, "1");
    SnmpObjId col2 = SnmpObjId.get(col2Base);
    SnmpObjId col2dot1 = SnmpObjId.get(col2, "1");
    SnmpObjId col2dot10 = SnmpObjId.get(col2, "10");
    SnmpObjId col3 = SnmpObjId.get(col3Base);
    SnmpObjId col3dot1 = SnmpObjId.get(col3, "1");
    SnmpObjId col3dot10 = SnmpObjId.get(col3, "10");
    assertEquals(z1dot0, m_agent.getFollowingObjId(z1));
    assertEquals(z2dot0, m_agent.getFollowingObjId(z1dot0));
    assertEquals(z2dot0, m_agent.getFollowingObjId(z2));
    assertEquals(col1dot1, m_agent.getFollowingObjId(z2dot0));
    assertEquals(col1dot1, m_agent.getFollowingObjId(col1));
    assertEquals(col3dot1, m_agent.getFollowingObjId(col2dot10));
    try {
        m_agent.getFollowingObjId(col3dot10);
        fail("Expected exception");
    } catch (NoSuchElementException e) {
    }
    m_agent.introduceSequenceError(col2dot10, col2dot1);
    assertEquals(col2dot1, m_agent.getFollowingObjId(col2dot10));
}
Also used : SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) NoSuchElementException(java.util.NoSuchElementException)

Example 70 with SnmpObjId

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

the class SnmpProxyRpcModule method get.

private CompletableFuture<SnmpResponseDTO> get(SnmpRequestDTO request, SnmpGetRequestDTO get) {
    final SnmpObjId[] oids = get.getOids().toArray(new SnmpObjId[get.getOids().size()]);
    final CompletableFuture<SnmpValue[]> future = SnmpUtils.getAsync(request.getAgent(), oids);
    return future.thenApply(values -> {
        final List<SnmpResult> results = new ArrayList<>(oids.length);
        for (int i = 0; i < oids.length; i++) {
            final SnmpResult result = new SnmpResult(oids[i], null, values[i]);
            results.add(result);
        }
        final SnmpResponseDTO responseDTO = new SnmpResponseDTO();
        responseDTO.setCorrelationId(get.getCorrelationId());
        responseDTO.setResults(results);
        return responseDTO;
    });
}
Also used : ArrayList(java.util.ArrayList) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpResult(org.opennms.netmgt.snmp.SnmpResult)

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