Search in sources :

Example 6 with Address

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

the class MockAgentTest method testWalkSystem.

public void testWalkSystem() throws IOException {
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    TableUtils walker = new TableUtils(snmp, new DefaultPDUFactory());
    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);
    // Implements snmp4j API
    @SuppressWarnings("rawtypes") List results = walker.getTable(target, new OID[] { new OID("1.3.6.1.2.1.1") }, null, null);
    assertNotNull(results);
    assertFalse(results.isEmpty());
    assertTrue(results.get(results.size() - 1) instanceof TableEvent);
    TableEvent lastEvent = (TableEvent) results.get(results.size() - 1);
    MockUtil.println("Status of lastEvent is " + lastEvent.getStatus());
    assertEquals(TableEvent.STATUS_OK, lastEvent.getStatus());
}
Also used : OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Address(org.snmp4j.smi.Address) UdpAddress(org.snmp4j.smi.UdpAddress) InetAddress(java.net.InetAddress) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OID(org.snmp4j.smi.OID) Target(org.snmp4j.Target) CommunityTarget(org.snmp4j.CommunityTarget) DefaultPDUFactory(org.snmp4j.util.DefaultPDUFactory) TableEvent(org.snmp4j.util.TableEvent) Snmp(org.snmp4j.Snmp) List(java.util.List) TableUtils(org.snmp4j.util.TableUtils) CommunityTarget(org.snmp4j.CommunityTarget)

Example 7 with Address

use of org.snmp4j.smi.Address 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)

Aggregations

Address (org.snmp4j.smi.Address)7 OctetString (org.snmp4j.smi.OctetString)7 CommunityTarget (org.snmp4j.CommunityTarget)4 GenericAddress (org.snmp4j.smi.GenericAddress)4 InetAddress (java.net.InetAddress)3 Snmp (org.snmp4j.Snmp)3 OID (org.snmp4j.smi.OID)3 UdpAddress (org.snmp4j.smi.UdpAddress)3 PDUv1 (org.snmp4j.PDUv1)2 Target (org.snmp4j.Target)2 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 MessageDispatcher (org.snmp4j.MessageDispatcher)1 MessageDispatcherImpl (org.snmp4j.MessageDispatcherImpl)1 PDU (org.snmp4j.PDU)1 TransportMapping (org.snmp4j.TransportMapping)1