/** * This method needs a valid root OID to return a VariableBinding list with the sub entities. * * @param rootID - The root OID * @return - a list containing VariableBinding */ public List<VariableBinding> getSubtree(OID rootID) throws TreeEventException { TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory()); treeUtils.setMaxRepetitions(Integer.MAX_VALUE); List<TreeEvent> events = treeUtils.getSubtree(authentication.getTarget(), rootID); // Get snmpwalk result. List<VariableBinding> varBindings = new ArrayList<VariableBinding>(); for (TreeEvent event : events) { if (event != null) { if (event.isError()) throw new TreeEventException("oid [" + rootID + "] " + event.getErrorMessage()); Collections.addAll(varBindings, event.getVariableBindings()); } } return varBindings; }
/** * The method get can be specified with an Array of requested OIDs. A Vector with elements of the * subclass VariableBinding will be returned. OID requested from the method GET can only return a * value. Therefore the OIDd must be a scalar and not a branch. * * @param oids - the requested OIDs * @return - a Vector with VariableBindings * @throws SNMPTimeOutException - will be thrown if a timeout with request happens * @throws PDURequestFailedException - will be thrown if an error occurs within the request * @see org.snmp4j.smi.VariableBinding */ public Vector<? extends VariableBinding> get(OID[] oids) throws SNMPTimeOutException, PDURequestFailedException { ResponseEvent responseEvent = null; Vector<? extends VariableBinding> vbs = null; try { // send the PDU responseEvent = snmp.send(createPDU(PDU.GET, oids), authentication.getTarget()); Logger.getLogger(SnmpManager.class.getName()).log(Level.INFO, responseEvent.toString()); } catch (IOException e) { System.err.println(e.getMessage()); } // extract the response PDU (could be null if timed out) if (responseEvent != null) { PDU responsePDU = responseEvent.getResponse(); if (checkResponsePDU(responsePDU)) vbs = responsePDU.getVariableBindings(); } else { throw new SNMPTimeOutException(); } return vbs; }