Search in sources :

Example 31 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class MapSubAgent method getNext.

@Override
public VariableBinding getNext(OID requested) {
    OID successor = nextOID(requested);
    SortedMap<OID, Variable> tailMap = m_values.tailMap(successor);
    if (tailMap.isEmpty()) {
        return null;
    }
    OID next = tailMap.firstKey();
    Variable value = tailMap.get(next);
    return new VariableBinding(next, value);
}
Also used : Variable(org.snmp4j.smi.Variable) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 32 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class MockSnmpAgentIT method requestAndVerifyResponse.

private void requestAndVerifyResponse(int pduType, int version) throws Exception {
    PDU pdu = createPDU(version);
    for (AnticipatedRequest a : m_requestedVarbinds) {
        pdu.add(a.getRequestVarbind());
    }
    pdu.setType(pduType);
    PDU response = sendRequest(pdu, version);
    assertNotNull("request timed out", response);
    System.err.println("Response is: " + response);
    assertTrue("unexpected report pdu: " + ((VariableBinding) response.getVariableBindings().get(0)).getOid(), response.getType() != PDU.REPORT);
    assertEquals("Unexpected number of varbinds returned.", m_requestedVarbinds.size(), response.getVariableBindings().size());
    for (int i = 0; i < m_requestedVarbinds.size(); i++) {
        AnticipatedRequest a = m_requestedVarbinds.get(i);
        VariableBinding vb = response.get(i);
        a.verify(vb);
    }
    reset();
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 33 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.

the class LLDPMibIT method requestAndVerifyResponse.

private void requestAndVerifyResponse(int pduType, int version) throws Exception {
    PDU pdu = createPDU(version);
    for (AnticipatedRequest a : m_requestedVarbinds) {
        pdu.add(a.getRequestVarbind());
    }
    pdu.setType(pduType);
    PDU response = sendRequest(pdu, version);
    assertNotNull("request timed out", response);
    System.err.println("Response is: " + response);
    assertTrue("unexpected report pdu: " + ((VariableBinding) response.getVariableBindings().get(0)).getOid(), response.getType() != PDU.REPORT);
    assertEquals("Unexpected number of varbinds returned.", m_requestedVarbinds.size(), response.getVariableBindings().size());
    for (int i = 0; i < m_requestedVarbinds.size(); i++) {
        AnticipatedRequest a = m_requestedVarbinds.get(i);
        VariableBinding vb = response.get(i);
        a.verify(vb);
    }
    reset();
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 34 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project Payara by payara.

the class SnmpNotificationRunnable method run.

@Override
public void run() {
    while (queue.size() > 0) {
        try {
            PDU pdu = DefaultPDUFactory.createPDU(snmpVersion);
            if (SnmpConstants.version1 == snmpVersion) {
                pdu.setType(PDU.V1TRAP);
            } else {
                pdu.setType(PDU.TRAP);
            }
            pdu.add(new VariableBinding(SnmpConstants.sysUpTime));
            OID oidInstance = new OID(executionOptions.getOid());
            pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, oidInstance));
            pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(executionOptions.getHost())));
            pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(new Date().toString())));
            SnmpMessage message = queue.getMessage();
            pdu.add(new VariableBinding(oidInstance, new OctetString(message.getSubject() + "\n" + message.getMessage())));
            snmp.send(pdu, communityTarget);
            logger.log(Level.FINE, "Message sent successfully");
        } catch (IOException e) {
            logger.log(Level.SEVERE, "IO Error while sending SNMP message", e);
        }
    }
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) IpAddress(org.snmp4j.smi.IpAddress) OID(org.snmp4j.smi.OID) IOException(java.io.IOException) VariableBinding(org.snmp4j.smi.VariableBinding) Date(java.util.Date)

Example 35 with VariableBinding

use of org.snmp4j.smi.VariableBinding in project camel by apache.

the class SnmpOIDPoller method poll.

@Override
protected int poll() throws Exception {
    this.pdu.clear();
    int type = this.getPduType(this.endpoint.getType());
    this.pdu.setType(type);
    // prepare the request items
    for (OID oid : this.endpoint.getOids()) {
        this.pdu.add(new VariableBinding(oid));
    }
    // send the request
    snmp.send(pdu, target, null, this);
    return 1;
}
Also used : OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

Aggregations

VariableBinding (org.snmp4j.smi.VariableBinding)52 OID (org.snmp4j.smi.OID)37 OctetString (org.snmp4j.smi.OctetString)31 PDU (org.snmp4j.PDU)30 ScopedPDU (org.snmp4j.ScopedPDU)17 Test (org.junit.Test)11 PDUv1 (org.snmp4j.PDUv1)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)8 ResponseEvent (org.snmp4j.event.ResponseEvent)8 Variable (org.snmp4j.smi.Variable)8 ArrayList (java.util.ArrayList)7 IpAddress (org.snmp4j.smi.IpAddress)7 TimeTicks (org.snmp4j.smi.TimeTicks)6 DefaultPDUFactory (org.snmp4j.util.DefaultPDUFactory)6 TableEvent (org.snmp4j.util.TableEvent)6 TableUtils (org.snmp4j.util.TableUtils)6 TrapInformation (org.opennms.netmgt.snmp.TrapInformation)5 Map (java.util.Map)4