/** * Perform a SNMP walk and returns the list of {@link TreeEvent} * @return the list of {@link TreeEvent} */ public List<TreeEvent> walk() { TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory()); @SuppressWarnings("unchecked") List<TreeEvent> events = treeUtils.getSubtree(this.target, this.oid); return events; }
/** * Perform a SNMP walk and returns the list of {@link TreeEvent} * @return the list of {@link TreeEvent} */ public List<TreeEvent> walk() { TreeUtils treeUtils = new TreeUtils(this.snmp, new DefaultPDUFactory()); @SuppressWarnings("unchecked") List<TreeEvent> events = treeUtils.getSubtree(this.target, this.oid); return events; }
/** * <p>Constructor for SnmpManager.</p> * * @param loader a {@link net.percederberg.mibble.MibLoader} object. * @param transportMappingAbstractFactory a {@link net.itransformers.snmp2xml4j.snmptoolkit.transport.TransportMappingAbstractFactory} object. * @param messageDispatcherAbstractFactory a {@link net.itransformers.snmp2xml4j.snmptoolkit.messagedispacher.MessageDispatcherAbstractFactory} object. * @param transportLocalIpAddress a {@link org.snmp4j.smi.TransportIpAddress} object. */ public SnmpManager(MibLoader loader, TransportMappingAbstractFactory transportMappingAbstractFactory, MessageDispatcherAbstractFactory messageDispatcherAbstractFactory, TransportIpAddress transportLocalIpAddress) { this.messageDispatcherFactory = new DefaultMessageDispatcherFactory(); this.transportMappingAbstractFactory = transportMappingAbstractFactory; this.messageDispatcherFactory = messageDispatcherAbstractFactory; this.pduFactory = new DefaultPDUFactory(); this.loader = loader; this.transportLocalIpAddress = transportLocalIpAddress; }
/** * <p>Constructor for SnmpManager.</p> * * @param loader a {@link net.percederberg.mibble.MibLoader} object. * @param retries a int. * @param timeout a int. * @param maxSizeRequestPDU a int. * @param maxRepetitions a int. * @param transportMappingAbstractFactory a {@link net.itransformers.snmp2xml4j.snmptoolkit.transport.TransportMappingAbstractFactory} object. * @param transportLocalIpAddress a {@link org.snmp4j.smi.TransportIpAddress} object. */ public SnmpManager(MibLoader loader, int retries, int timeout, int maxSizeRequestPDU, int maxRepetitions, TransportMappingAbstractFactory transportMappingAbstractFactory, TransportIpAddress transportLocalIpAddress) { this.retries = retries; this.timeout = timeout; this.maxSizeRequestPDU = maxSizeRequestPDU; this.messageDispatcherFactory = new DefaultMessageDispatcherFactory(); this.transportMappingAbstractFactory = transportMappingAbstractFactory; this.pduFactory = new DefaultPDUFactory(); this.transportLocalIpAddress = transportLocalIpAddress; this.maxRepetitions = maxRepetitions; this.loader = loader; } /**
public MOSubtreeProxy(Session session, SnmpTargetMIB targetMIB, OctetString proxyName, OID subtreeOID, OctetString contextEngineID, OctetString contextName, OctetString targetName) { this.session = session; this.targetMIB = targetMIB; this.proxyName = proxyName; this.contextName = contextName; this.scope = new DefaultMOScope(subtreeOID, true, subtreeOID.nextPeer(), false); this.targetName = targetName; this.contextEngineID = contextEngineID; this.pduFactory = new DefaultPDUFactory(PDU.GETNEXT, contextEngineID, contextName); }
/** * Normally this would return domain objects or something else than this... */ public List<List<String>> getTableAsStrings(OID[] oids) { TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory()); @SuppressWarnings("unchecked") List<TableEvent> events = tUtils.getTable(getTarget(), oids, null, null); List<List<String>> list = new ArrayList<List<String>>(); for (TableEvent event : events) { if(event.isError()) { throw new RuntimeException(event.getErrorMessage()); } List<String> strList = new ArrayList<String>(); list.add(strList); for(VariableBinding vb: event.getColumns()) { strList.add(vb.getVariable().toString()); } } return list; }
public TabularIterator(SnmpConnection starter, Collection<OID> oids) { if(starter != null && starter.isStarted()) { Target snmpTarget = starter.getConnection(); if(snmpTarget != null) { DefaultPDUFactory localfactory = new DefaultPDUFactory(); TableUtils tableRet = new TableUtils(starter.getSnmp(), localfactory); tableRet.setMaxNumColumnsPerPDU(30); OID[] oidTab = new OID[oids.size()]; oids.toArray(oidTab); tabIterator = tableRet.getTable(snmpTarget, oidTab, null, null).iterator(); } } }
TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory()); for (OID oid : this.endpoint.getOids()) { List events = treeUtils.getSubtree(target, new OID(oid));
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()); }