Search in sources :

Example 11 with CommunityTarget

use of org.snmp4j.CommunityTarget in project camel by apache.

the class SnmpProducer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
    LOG.debug("targetAddress: {}", targetAddress);
    this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(this.usm);
    // setting up target
    this.target = new CommunityTarget();
    this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
    this.target.setAddress(this.targetAddress);
    this.target.setRetries(this.endpoint.getRetries());
    this.target.setTimeout(this.endpoint.getTimeout());
    this.target.setVersion(this.endpoint.getSnmpVersion());
    this.pdu = new PDU();
    for (OID oid : this.endpoint.getOids()) {
        this.pdu.add(new VariableBinding(oid));
    }
    this.pdu.setErrorIndex(0);
    this.pdu.setErrorStatus(0);
    this.pdu.setMaxRepetitions(0);
    this.pdu.setType(PDU.GET);
}
Also used : OctetString(org.snmp4j.smi.OctetString) PDU(org.snmp4j.PDU) OID(org.snmp4j.smi.OID) CommunityTarget(org.snmp4j.CommunityTarget) VariableBinding(org.snmp4j.smi.VariableBinding) USM(org.snmp4j.security.USM)

Example 12 with CommunityTarget

use of org.snmp4j.CommunityTarget in project camel by apache.

the class SnmpTrapProducer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
    LOG.debug("targetAddress: {}", targetAddress);
    this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(this.usm);
    // setting up target
    this.target = new CommunityTarget();
    this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
    this.target.setAddress(this.targetAddress);
    this.target.setRetries(this.endpoint.getRetries());
    this.target.setTimeout(this.endpoint.getTimeout());
    this.target.setVersion(this.endpoint.getSnmpVersion());
}
Also used : OctetString(org.snmp4j.smi.OctetString) CommunityTarget(org.snmp4j.CommunityTarget) USM(org.snmp4j.security.USM)

Example 13 with CommunityTarget

use of org.snmp4j.CommunityTarget in project opennms by OpenNMS.

the class MockAgentTest method testGetSysName.

public void testGetSysName() throws IOException {
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.listen();
    Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
    //Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
    Target target = new CommunityTarget(addr, new OctetString("public"));
    target.setVersion(SnmpConstants.version1);
    target.setTimeout(3000);
    target.setRetries(3);
    PDUv1 getRequest = new PDUv1();
    getRequest.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
    ResponseEvent e = snmp.get(getRequest, target);
    PDU response = e.getResponse();
    assertEquals(new OctetString("mockhost"), response.get(0).getVariable());
}
Also used : OctetString(org.snmp4j.smi.OctetString) PDU(org.snmp4j.PDU) UdpAddress(org.snmp4j.smi.UdpAddress) Target(org.snmp4j.Target) CommunityTarget(org.snmp4j.CommunityTarget) Address(org.snmp4j.smi.Address) UdpAddress(org.snmp4j.smi.UdpAddress) InetAddress(java.net.InetAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) PDUv1(org.snmp4j.PDUv1) OID(org.snmp4j.smi.OID) CommunityTarget(org.snmp4j.CommunityTarget) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 14 with CommunityTarget

use of org.snmp4j.CommunityTarget in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV1V2.

private PDU sendRequestV1V2(PDU pdu, int version) throws Exception {
    PDU response;
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(version);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) CommunityTarget(org.snmp4j.CommunityTarget)

Aggregations

CommunityTarget (org.snmp4j.CommunityTarget)14 OctetString (org.snmp4j.smi.OctetString)12 PDU (org.snmp4j.PDU)8 Snmp (org.snmp4j.Snmp)8 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)7 UdpAddress (org.snmp4j.smi.UdpAddress)6 OID (org.snmp4j.smi.OID)5 ScopedPDU (org.snmp4j.ScopedPDU)4 ResponseEvent (org.snmp4j.event.ResponseEvent)4 Address (org.snmp4j.smi.Address)4 VariableBinding (org.snmp4j.smi.VariableBinding)4 InetAddress (java.net.InetAddress)3 USM (org.snmp4j.security.USM)3 IOException (java.io.IOException)2 SnmpBindingProvider (org.openhab.binding.snmp.SnmpBindingProvider)2 PDUv1 (org.snmp4j.PDUv1)2 Target (org.snmp4j.Target)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1