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()); }
@Override protected void tearDown() throws Exception { m_proxy.stop(); /* * Future calls to setUp() fail due to the port still being in use * if I don't have the sleep: * * OpenJDK Runtime Environment (build 1.8.0_45-b13) on Amazon Linux AMI release 2015.03 * * I hate it when resources don't get fully deallocated. */ Thread.sleep(5); MockLogAppender.assertNoWarningsOrGreater(); MockUtil.println("------------ End Test "+getName()+" --------------------------"); }
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()); }
@Override protected void setUp() throws Exception { MockUtil.println("------------ Begin Test "+getName()+" --------------------------"); MockLogAppender.setupLogging();