org.snmp4j.PDU.getErrorStatus()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中org.snmp4j.PDU.getErrorStatus()方法的一些代码示例,展示了PDU.getErrorStatus()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PDU.getErrorStatus()方法的具体详情如下:
包路径:org.snmp4j.PDU
类名称:PDU
方法名:getErrorStatus

PDU.getErrorStatus介绍

[英]Gets the error status of the PDU.
[中]获取PDU的错误状态。

代码示例

代码示例来源:origin: apache/nifi

processSession.getProvenanceReporter().receive(flowFile,
    this.snmpTarget.getAddress().toString() + "/" + context.getProperty(OID).getValue());
if(pdu.getErrorStatus() == PDU.noError) {
  processSession.transfer(flowFile, REL_SUCCESS);
} else {

代码示例来源:origin: apache/nifi

this.getLogger().error("Set request timed out or parameters are incorrect.");
  context.yield();
} else if(response.getResponse().getErrorStatus() == PDU.noError) {
  flowFile = SNMPUtils.updateFlowFileAttributesWithPduProperties(pdu, flowFile, processSession);
  processSession.transfer(flowFile, REL_SUCCESS);

代码示例来源:origin: com.rogueai/snmp2bean

protected void checkResponseError(PDU responsePDU) throws SnmpException {
  if (responsePDU == null) {
    SnmpException e = new SnmpException(SnmpException.NO_RESPONSE_PDU, -1);
    e.setSnmpErrorMsgProvider(getSnmpErrorMsgProvider());
    throw e;
  }
  if (responsePDU.getErrorStatus() != 0) {
    SnmpException e = new SnmpException(responsePDU.getErrorStatus(), responsePDU.getErrorIndex());
    e.setSnmpErrorMsgProvider(getSnmpErrorMsgProvider());
    throw e;
  }
}

代码示例来源:origin: OpenNMS/opennms

private void processResponse(final PDU response) throws SnmpException {
  try {
    LOG.debug("Received a tracker PDU of type {} from {} of size {}, errorStatus = {}, errorStatusText = {}, errorIndex = {}", PDU.getTypeString(response.getType()), getAddress(), response.size(), response.getErrorStatus(), response.getErrorStatusText(), response.getErrorIndex());
    if (response.getType() == PDU.REPORT) {
      handleAuthError("A REPORT PDU was returned from the agent.  This is most likely an authentication problem.  Please check the config");
    } else {
      if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) {
        if (response.size() == 0) { // NMS-6484
          handleError("A PDU with no errors and 0 varbinds was returned from the agent at " + getAddress() + ". This seems to be related with a broken SNMP agent.");
        } else {
          for (int i = 0; i < response.size(); i++) {
            final VariableBinding vb = response.get(i);
            final SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue());
            final SnmpValue val = new Snmp4JValue(vb.getVariable());
            Snmp4JWalker.this.processResponse(receivedOid, val);
          }
        }
      }
      buildAndSendNextPdu();
    }
  } catch (final RuntimeException|SnmpException e) {
    handleFatalError(e);
  }
}

代码示例来源:origin: org.snmp4j/snmp4j

@Override
 public void onResponse(ResponseEvent event) {
  SnmpUriResponse response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
  PDU responsePDU = event.getResponse();
  if (responsePDU != null) {
   if (responsePDU.getErrorStatus() != PDU.noError) {
    response = new SnmpUriResponse(responsePDU.getErrorStatus());
   }
   else {
    response = new SnmpUriResponse(
      Collections.<VariableBinding[]>singletonList(
        responsePDU.getVariableBindings().toArray(new VariableBinding[responsePDU.size()])));
   }
  }
  callback.onResponse(response, url , event.getUserObject());
 }
}

代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j

private void processResponse(final PDU response) throws SnmpException {
  try {
    LOG.debug("Received a tracker PDU of type {} from {} of size {}, errorStatus = {}, errorStatusText = {}, errorIndex = {}", PDU.getTypeString(response.getType()), getAddress(), response.size(), response.getErrorStatus(), response.getErrorStatusText(), response.getErrorIndex());
    if (response.getType() == PDU.REPORT) {
      handleAuthError("A REPORT PDU was returned from the agent.  This is most likely an authentication problem.  Please check the config");
    } else {
      if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) {
        if (response.size() == 0) { // NMS-6484
          handleError("A PDU with no errors and 0 varbinds was returned from the agent at " + getAddress() + ". This seems to be related with a broken SNMP agent.");
        } else {
          for (int i = 0; i < response.size(); i++) {
            final VariableBinding vb = response.get(i);
            final SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue());
            final SnmpValue val = new Snmp4JValue(vb.getVariable());
            Snmp4JWalker.this.processResponse(receivedOid, val);
          }
        }
      }
      buildAndSendNextPdu();
    }
  } catch (final RuntimeException|SnmpException e) {
    handleFatalError(e);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

@Override
 public void onResponse(ResponseEvent event) {
  SnmpUriResponse response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
  PDU responsePDU = event.getResponse();
  if (responsePDU != null) {
   if (responsePDU.getErrorStatus() != PDU.noError) {
    response = new SnmpUriResponse(responsePDU.getErrorStatus());
   }
   else {
    response = new SnmpUriResponse(
      Collections.<VariableBinding[]>singletonList(
        responsePDU.getVariableBindings().toArray(new VariableBinding[responsePDU.size()])));
   }
  }
  callback.onResponse(response, url , event.getUserObject());
 }
}

代码示例来源:origin: org.opennms.lib.snmp/org.opennms.lib.snmp.snmp4j

private void processResponse(PDU response) {
  try {
    if (log().isDebugEnabled()) {
      log().debug("Received a tracker PDU of type "+PDU.getTypeString(response.getType())+" from "+getAddress()+" of size "+response.size()+", errorStatus = "+response.getErrorStatus()+", errorStatusText = "+response.getErrorStatusText()+", errorIndex = "+response.getErrorIndex());
    }
    if (response.getType() == PDU.REPORT) {
      handleAuthError("A REPORT PDU was returned from the agent.  This is most likely an authentication problem.  Please check the config");
    } else {
      if (!processErrors(response.getErrorStatus(), response.getErrorIndex())) {
        for (int i = 0; i < response.size(); i++) {
          VariableBinding vb = response.get(i);
          SnmpObjId receivedOid = SnmpObjId.get(vb.getOid().getValue());
          SnmpValue val = new Snmp4JValue(vb.getVariable());
          Snmp4JWalker.this.processResponse(receivedOid, val);
        }
      }
      buildAndSendNextPdu();
    }
  } catch (Throwable e) {
    handleFatalError(e);
  }
}

代码示例来源:origin: org.snmp4j/snmp4j

private SnmpUriResponse sendSnmpRequest(Request request, PDU pdu) {
 SnmpUriResponse response =  new SnmpUriResponse(PDU.genErr);
 try {
  ResponseEvent responseEvent = snmp.send(pdu, request.getTarget());
  if (responseEvent != null) {
   PDU responsePDU = responseEvent.getResponse();
   if (responsePDU != null) {
    if (responsePDU.getErrorStatus() != PDU.noError) {
     response = new SnmpUriResponse(responsePDU.getErrorStatus());
    }
    else {
     response = new SnmpUriResponse(
       Collections.<VariableBinding[]>singletonList(
         responsePDU.getVariableBindings().toArray(new VariableBinding[responsePDU.size()])));
    }
   }
   else {
    response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
   }
  }
  else {
   response = new SnmpUriResponse(SnmpUriResponse.Type.FINAL);
  }
 } catch (IOException e) {
  e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 }
 return response;
}

代码示例来源:origin: org.snmp4j/snmp4j-agent

@Override
public void undo(SubRequest request) {
 VariableBinding vb = (VariableBinding) request.getUndoValue();
 if (vb != null) {
  Target target = targetMIB.getTarget(targetName, contextEngineID, contextName);
  PDU pdu = pduFactory.createPDU(target);
  pdu.setType(PDU.SET);
  pdu.add(vb);
  try {
   ResponseEvent resp = session.send(pdu, target);
   if (resp.getResponse() != null) {
    PDU rpdu = resp.getResponse();
    if (rpdu.getErrorStatus() != PDU.noError) {
     request.setErrorStatus(PDU.undoFailed);
     logger.warn("Undo failed because target '"+target+"' returned error "+rpdu.getErrorStatusText());
    }
   }
   else {
    request.setErrorStatus(PDU.genErr);
   }
  } catch (IOException e) {
   request.setErrorStatus(PDU.genErr);
   logger.error("IOException in undo SET sub-request " + request + " to " + target, e);
  }
 }
 else if (undoEnabled) {
  request.setErrorStatus(PDU.undoFailed);
 }
 request.getStatus().setPhaseComplete(true);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

private SnmpUriResponse sendSnmpRequest(Request request, PDU pdu) {
 SnmpUriResponse response =  new SnmpUriResponse(PDU.genErr);
 try {
  ResponseEvent responseEvent = snmp.send(pdu, request.getTarget());
  if (responseEvent != null) {
   PDU responsePDU = responseEvent.getResponse();
   if (responsePDU != null) {
    if (responsePDU.getErrorStatus() != PDU.noError) {
     response = new SnmpUriResponse(responsePDU.getErrorStatus());
    }
    else {
     response = new SnmpUriResponse(
       Collections.<VariableBinding[]>singletonList(
         responsePDU.getVariableBindings().toArray(new VariableBinding[responsePDU.size()])));
    }
   }
   else {
    response = new SnmpUriResponse(SnmpUriResponse.Type.TIMEOUT);
   }
  }
  else {
   response = new SnmpUriResponse(SnmpUriResponse.Type.FINAL);
  }
 } catch (IOException e) {
  e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
 }
 return response;
}

代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit

/**
 * <p>getNext.</p>
 *
 * @param oids an array of {@link org.snmp4j.smi.OID} objects.
 * @return a {@link org.snmp4j.event.ResponseEvent} object.
 * @throws java.io.IOException if any.
 */
public ResponseEvent snmpGetNext(OID oids[]) throws IOException {
  PDU pdu =  pduFactory.createPDU(getTarget());
  for (OID oid : oids) {
    pdu.add(new VariableBinding(oid));
  }
  pdu.setType(PDU.GETNEXT);
  ResponseEvent response;
  response = snmp.send(pdu, getTarget());
  if (response != null) {
    PDU responsePDU = response.getResponse();
    if (responsePDU != null) {
      if (responsePDU.getErrorStatus() == PDU.noError) {
        return response;
      }
    }
    logger.log(Priority.INFO, "GET reposne from " + getTarget().getAddress() + " was null!");
    return null;
  }
  logger.log(Priority.INFO, "GET from " + getTarget().getAddress() + " has timed out!");
  return null;
}

代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit

/**
 * <p>snmpGet.</p>
 *
 * @param oids an array of {@link org.snmp4j.smi.OID} objects.
 * @return a {@link org.snmp4j.event.ResponseEvent} object.
 * @throws java.io.IOException if any.
 */
public ResponseEvent snmpGet(OID oids[]) throws IOException {
  PDU pdu =  pduFactory.createPDU(getTarget());
  for (OID oid : oids) {
    pdu.add(new VariableBinding(oid));
  }
  pdu.setType(PDU.GET);
  ResponseEvent response;
  response = snmp.send(pdu, getTarget());
  if (response != null) {
    PDU responsePDU = response.getResponse();
    if (responsePDU != null) {
      if (responsePDU.getErrorStatus() == PDU.noError) {
        return response;
      }
    }
    logger.log(Priority.INFO, "GET reposne from " + getTarget().getAddress() + " was null!");
    return null;
  }
  logger.log(Priority.INFO, "GET from " + getTarget().getAddress() + " has timed out!");
  return null;
}

代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit

/**
 * <p>snmpGet.</p>
 *
 * @param oidString a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 * @throws java.io.IOException if any.
 */
public String snmpGet(String oidString) throws IOException {
  OID oid = new OID(oidString);
  PDU pdu =  pduFactory.createPDU(getTarget());
  pdu.add(new VariableBinding(oid));
  pdu.setType(PDU.GET);
  ResponseEvent response;
  response = snmp.send(pdu, getTarget());
  if (response != null) {
    PDU responsePDU = response.getResponse();
    if (responsePDU != null) {
      if (responsePDU.getErrorStatus() == PDU.noError) {
         return responsePDU.get(0).toValueString();
      }
    }
    logger.info("GET reposne from " + getTarget().getAddress() + " was null!");
    return null;
  }
  logger.info("GET from " + getTarget().getAddress() + " has timed out!");
  return null;
}

代码示例来源:origin: net.itransformers.snmp2xml4j/snmptoolkit

/**
 * <p>getNext.</p>
 *
 * @param oidString a {@link java.lang.String} object.
 * @return a {@link java.lang.String} object.
 * @throws java.io.IOException if any.
 */
public String snmpGetNext(String oidString) throws IOException {
  OID oid = new OID(oidString);
  PDU pdu =  pduFactory.createPDU(getTarget());
  pdu.add(new VariableBinding(oid));
  pdu.setType(PDU.GETNEXT);
  ResponseEvent response;
  response = snmp.send(pdu, getTarget());
  if (response != null) {
    PDU responsePDU = response.getResponse();
    if (responsePDU != null) {
      if (responsePDU.getErrorStatus() == PDU.noError) {
        return responsePDU.get(0).toValueString();
      }
    }
    logger.info("GET reposne from " + getTarget().getAddress() + " was null!");
    return null;
  }
  logger.info("GET from " + getTarget().getAddress() + " has timed out!");
  return null;
}

代码示例来源:origin: org.snmp4j/snmp4j-agent

@Override
public void commit(SubRequest request) {
 OID oid = request.getVariableBinding().getOid();
 if (translation != null) {
  oid = translation.forwardTranslate(oid);
 }
 VariableBinding vb = new VariableBinding(oid, request.getVariableBinding().getVariable());
 Target target = targetMIB.getTarget(targetName, contextEngineID, contextName);
 PDU pdu = pduFactory.createPDU(target);
 pdu.setType(PDU.SET);
 pdu.add(vb);
 try {
  ResponseEvent resp = session.send(pdu, target);
  if (resp.getResponse() != null) {
   PDU rpdu = resp.getResponse();
   if (rpdu.getErrorStatus() != PDU.noError) {
    request.setErrorStatus(rpdu.getErrorStatus());
   }
   request.getStatus().setPhaseComplete(true);
  }
  else {
   request.setErrorStatus(PDU.genErr);
  }
 } catch (IOException e) {
  request.setErrorStatus(PDU.genErr);
  logger.error("IOException in commit SET sub-request " + request + " to " + target, e);
 }
}

代码示例来源:origin: org.kaazing/snmp4j

protected boolean checkResponse(ResponseEvent event) {
 if (event.getError() != null) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject, event.getError()));
 }
 else if (event.getResponse() == null) {
  finished = true;
  // timeout
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   TableEvent.STATUS_TIMEOUT));
 }
 else if (event.getResponse().getType() == PDU.REPORT) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   event.getResponse()));
 }
 else if (event.getResponse().getErrorStatus() != PDU.noError) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   event.getResponse().getErrorStatus()));
 }
 else {
  return true;
 }
 return false;
}

代码示例来源:origin: org.snmp4j/snmp4j

protected boolean checkResponse(ResponseEvent event) {
  if (event.getError() != null) {
    finished = true;
    emptyCache();
    listener.finished(new TableEvent(this, userObject, event.getError()));
  } else if (event.getResponse() == null) {
    finished = true;
    // timeout
    emptyCache();
    listener.finished(new TableEvent(this, userObject,
        TableEvent.STATUS_TIMEOUT));
  } else if (event.getResponse().getType() == PDU.REPORT) {
    finished = true;
    emptyCache();
    listener.finished(new TableEvent(this, userObject,
        event.getResponse()));
  } else if (event.getResponse().getErrorStatus() != PDU.noError) {
    finished = true;
    emptyCache();
    listener.finished(new TableEvent(this, userObject,
        event.getResponse().getErrorStatus()));
  } else {
    return true;
  }
  return false;
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.snmp4j

protected boolean checkResponse(ResponseEvent event) {
 if (event.getError() != null) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject, event.getError()));
 }
 else if (event.getResponse() == null) {
  finished = true;
  // timeout
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   TableEvent.STATUS_TIMEOUT));
 }
 else if (event.getResponse().getType() == PDU.REPORT) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   event.getResponse()));
 }
 else if (event.getResponse().getErrorStatus() != PDU.noError) {
  finished = true;
  emptyCache();
  listener.finished(new TableEvent(this, userObject,
                   event.getResponse().getErrorStatus()));
 }
 else {
  return true;
 }
 return false;
}

代码示例来源:origin: org.snmp4j/snmp4j-agent

if (resp.getResponse() != null) {
 PDU rpdu = resp.getResponse();
 if (rpdu.getErrorStatus() != PDU.noError) {
  request.setErrorStatus(rpdu.getErrorStatus());

相关文章