コード例 #1
0
ファイル: SnmpV3.java プロジェクト: aaly-tgm/rtn
  /**
   * 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;
  }
コード例 #2
0
ファイル: SnmpURI.java プロジェクト: hikumar/snmp4j
 @Override
 public boolean next(TreeEvent event) {
   if (!finished) {
     SnmpUriResponse response = createResponse(event);
     finished |= callback.onResponse(response, url, event.getUserObject());
   }
   return !finished;
 }
コード例 #3
0
ファイル: SnmpURI.java プロジェクト: hikumar/snmp4j
 @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;
   }
 }
コード例 #4
0
ファイル: SnmpURI.java プロジェクト: hikumar/snmp4j
 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;
 }