Exemple #1
0
  /**
   * 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;
  }
Exemple #2
0
 @Override
 public boolean next(TreeEvent event) {
   if (!finished) {
     SnmpUriResponse response = createResponse(event);
     finished |= callback.onResponse(response, url, event.getUserObject());
   }
   return !finished;
 }
Exemple #3
0
 @Override
 public void finished(TreeEvent event) {
   if (!finished) {
     SnmpUriResponse response = createResponse(event);
     if (response.getResponseType() == SnmpUriResponse.Type.NEXT) {
       response.setResponseType(SnmpUriResponse.Type.FINAL);
     }
     callback.onResponse(response, url, event.getUserObject());
     finished = true;
   }
 }
Exemple #4
0
 private SnmpUriResponse createResponse(TreeEvent event) {
   SnmpUriResponse response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
   if (event.getStatus() == TreeEvent.STATUS_OK) {
     VariableBinding[] vbs = event.getVariableBindings();
     int errorStatus = event.getStatus();
     response = new SnmpUriResponse(Collections.singletonList(vbs), errorStatus);
     if (errorStatus == PDU.noError) {
       response.setResponseType(SnmpUriResponse.Type.NEXT);
     }
   } else if (event.getStatus() == TreeEvent.STATUS_EXCEPTION) {
     response =
         new SnmpUriResponse(SnmpUriResponse.Type.IO_ERROR, event.getException().getMessage());
   } else if (event.getStatus() == TreeEvent.STATUS_REPORT) {
     response =
         new SnmpUriResponse(
             SnmpUriResponse.Type.SECURITY_ERROR,
             (event.getReportPDU().size() > 0
                 ? event.getReportPDU().get(0).toString()
                 : "<empty report PDU>"));
   } else if (event.getStatus() == TreeEvent.STATUS_WRONG_ORDER) {
     response = new SnmpUriResponse(SnmpUriResponse.Type.LEXICOGRAPHIC_ORDER_ERROR);
   }
   return response;
 }