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());
}
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());
}
Aggregations