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

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

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

PDU.setErrorStatus介绍

[英]Sets the error status of the PDU.
[中]设置PDU的错误状态。

代码示例

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

case SnmpConstants.SNMP_ERROR_NO_CREATION:
 case SnmpConstants.SNMP_ERROR_INCONSISTENT_NAME: {
  response.setErrorStatus(SnmpConstants.SNMP_ERROR_NO_SUCH_NAME);
  break;
 case SnmpConstants.SNMP_ERROR_COMMIT_FAILED:
 case SnmpConstants.SNMP_ERROR_UNDO_FAILED: {
  response.setErrorStatus(SnmpConstants.SNMP_ERROR_GENERAL_ERROR);
  break;
 case SnmpConstants.SNMP_ERROR_INCONSISTENT_VALUE:
 case SnmpConstants.SNMP_ERROR_WRONG_TYPE: {
  response.setErrorStatus(SnmpConstants.SNMP_ERROR_BAD_VALUE);
  break;
  response.setErrorStatus(errStatus);
 VariableBinding vb = response.get(i);
 if (vb.isException()) {
  response.setErrorStatus(PDU.noSuchName);
  response.setErrorIndex(i+1);
  response.set(i, new VariableBinding(vb.getOid()));
response.setErrorStatus(errStatus);

代码示例来源:origin: org.jboss.jbossas/jboss-snmp

/** This utility method is used to construct an error PDU. This code
 * was repeated so many times it was prudent to give it it's own method.
 * @param response This PDU is the one being modified into an error PDU.
 * @param oid The OID to contain the error Null instance.
 * @param errorIndex the VariableBinding in the PDU that caused the error. 
 * @param err The error number defined in the PDU class that indicates a given failure
 */
private void makeErrorPdu(PDU response, PDU pdu, int errorIndex, int err){
  response.clear();
  response.addAll(pdu.toArray());
  response.setErrorIndex(errorIndex);
  response.setErrorStatus(err);
}

代码示例来源:origin: org.mobicents.tools.snmp.adaptor/core

/** This utility method is used to construct an error PDU. This code
 * was repeated so many times it was prudent to give it it's own method.
 * @param response This PDU is the one being modified into an error PDU.
 * @param oid The OID to contain the error Null instance.
 * @param errorIndex the VariableBinding in the PDU that caused the error. 
 * @param err The error number defined in the PDU class that indicates a given failure
 */
private void makeErrorPdu(PDU response, PDU pdu, int errorIndex, int err){
  response.clear();
  response.addAll(pdu.toArray());
  response.setErrorIndex(errorIndex);
  response.setErrorStatus(err);
}

代码示例来源:origin: org.apache.camel/camel-snmp

trap.setErrorStatus(0);
trap.setMaxRepetitions(0);
if (this.endpoint.getSnmpVersion() == SnmpConstants.version1) {

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

private PDU createResponse() {
 PDU resp = (PDU) source.getPDU().clone();
 resp.clear();
 resp.setType(PDU.RESPONSE);
 resp.setRequestID(source.getPDU().getRequestID());
 resp.setErrorIndex(0);
 resp.setErrorStatus(PDU.noError);
 return resp;
}

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

private PDU createResponse() {
 PDU resp = (PDU) requestEvent.getPDU().clone();
 resp.clear();
 resp.setType(PDU.RESPONSE);
 resp.setRequestID(requestEvent.getPDU().getRequestID());
 resp.setErrorIndex(0);
 resp.setErrorStatus(PDU.noError);
 return resp;
}

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

/**
 * @param request
 * @return
 */
private PDU processGetNext(PDU request) {
  PDU response = request;
  response.setErrorIndex(0);
  response.setErrorStatus(0);
  response.setType(PDU.RESPONSE);
  
  Vector<? extends VariableBinding> varBinds = response.getVariableBindings();
  for(int i = 0; i < varBinds.size(); i++) {
    VariableBinding varBind = varBinds.get(i);
    VariableBinding nextVarBind = m_agent.getNext(varBind.getOid());
    if (nextVarBind == null) {
      if (response instanceof PDUv1) {
        if (response.getErrorIndex() == 0) {
          response.setErrorIndex(i+1);
          response.setErrorStatus(PDU.noSuchName);
        } 
      } else {
        varBind.setVariable(Null.endOfMibView);
      }
    } else {
      response.set(i, nextVarBind);
    }
  }
  
  return response;
}

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

command.setErrorStatus(0);
command.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
  command.setErrorStatus(errorStatus);
  command.setType(type);

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

/**
 * @param request
 * @return
 */
private PDU processGet(PDU request) {
  PDU response = request;
  response.setErrorIndex(0);
  response.setErrorStatus(0);
  response.setType(PDU.RESPONSE);
  
  Vector<? extends VariableBinding> varBinds = response.getVariableBindings();
  for(int i = 0; i < varBinds.size(); i++) {
    VariableBinding varBind = varBinds.get(i);
    VariableBinding nextVarBind = m_agent.get(varBind.getOid());
    if (nextVarBind == null) {
      if (response instanceof PDUv1) {
        if (response.getErrorIndex() == 0) {
          response.setErrorIndex(i+1);
          response.setErrorStatus(PDU.noSuchName);
        } 
      } else {
        varBind.setVariable(Null.endOfMibView);
      }
    } else {
      response.set(i, nextVarBind);
    }
  }
  
  return response;
}

代码示例来源:origin: org.apache.camel/camel-snmp

pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();

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

public synchronized void processPdu(CommandResponderEvent e) {
  PDU command = e.getPDU();
  if (command != null) {
    if ((command.getType() != PDU.TRAP) &&
        (command.getType() != PDU.V1TRAP) &&
        (command.getType() != PDU.REPORT) &&
        (command.getType() != PDU.RESPONSE)) {
      out.println(command.toString());
      command.setErrorIndex(0);
      command.setErrorStatus(0);
      command.setType(PDU.RESPONSE);
      StatusInformation statusInformation = new StatusInformation();
      StateReference ref = e.getStateReference();
      try {
        e.getMessageDispatcher().returnResponsePdu(e.
                getMessageProcessingModel(),
            e.getSecurityModel(),
            e.getSecurityName(),
            e.getSecurityLevel(),
            command,
            e.getMaxSizeResponsePDU(),
            ref,
            statusInformation);
      } catch (MessageException ex) {
        err.println("Error while sending response: " + ex.getMessage());
        LogFactory.getLogger(SnmpCommand.class).error(ex);
      }
    }
  }
}

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

/**
  * Sends a RESPONSE PDU to the source address of a INFORM request.
  * @param event
  *    the <code>CommandResponderEvent</code> with the INFORM request.
  * @throws
  *    MessageException if the response could not be created and sent.
  */
 protected void sendInformResponse(CommandResponderEvent event) throws
   MessageException {
  PDU responsePDU = (PDU) event.getPDU().clone();
  responsePDU.setType(PDU.RESPONSE);
  responsePDU.setErrorStatus(PDU.noError);
  responsePDU.setErrorIndex(0);
  messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(),
                    event.getSecurityModel(),
                    event.getSecurityName(),
                    event.getSecurityLevel(),
                    responsePDU,
                    event.getMaxSizeResponsePDU(),
                    event.getStateReference(),
                    new StatusInformation());
 }
}

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

public synchronized void processPdu(CommandResponderEvent e) {
 PDU command = e.getPDU();
 if (command != null) {
  System.out.println(command.toString());
  if ((command.getType() != PDU.TRAP) &&
    (command.getType() != PDU.V1TRAP) &&
    (command.getType() != PDU.REPORT) &&
    (command.getType() != PDU.RESPONSE)) {
   command.setErrorIndex(0);
   command.setErrorStatus(0);
   command.setType(PDU.RESPONSE);
   StatusInformation statusInformation = new StatusInformation();
   StateReference ref = e.getStateReference();
   try {
    e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
                          e.getSecurityModel(),
                          e.getSecurityName(),
                          e.getSecurityLevel(),
                          command,
                          e.getMaxSizeResponsePDU(),
                          ref,
                          statusInformation);
   }
   catch (MessageException ex) {
    System.err.println("Error while sending response: "+ex.getMessage());
    LogFactory.getLogger(SnmpRequest.class).error(ex);
   }
  }
 }
}

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

(command.getType() != PDU.RESPONSE)) {
command.setErrorIndex(0);
command.setErrorStatus(0);
command.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();

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

/**
  * Sends a RESPONSE PDU to the source address of a INFORM request.
  * @param event
  *    the <code>CommandResponderEvent</code> with the INFORM request.
  * @throws
  *    MessageException if the response could not be created and sent.
  */
 protected void sendInformResponse(CommandResponderEvent event) throws
   MessageException {
  PDU responsePDU = (PDU) event.getPDU().clone();
  responsePDU.setType(PDU.RESPONSE);
  responsePDU.setErrorStatus(PDU.noError);
  responsePDU.setErrorIndex(0);
  messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(),
                    event.getSecurityModel(),
                    event.getSecurityName(),
                    event.getSecurityLevel(),
                    responsePDU,
                    event.getMaxSizeResponsePDU(),
                    event.getStateReference(),
                    new StatusInformation());
 }
}

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

/**
   * Sends a RESPONSE PDU to the source address of a INFORM request.
   *
   * @param event
   *         the <code>CommandResponderEvent</code> with the INFORM request.
   *
   * @throws MessageException
   *         if the response could not be created and sent.
   */
  protected void sendInformResponse(CommandResponderEvent event) throws
      MessageException {
    PDU responsePDU = (PDU) event.getPDU().clone();
    responsePDU.setType(PDU.RESPONSE);
    responsePDU.setErrorStatus(PDU.noError);
    responsePDU.setErrorIndex(0);
    messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(),
        event.getSecurityModel(),
        event.getSecurityName(),
        event.getSecurityLevel(),
        responsePDU,
        event.getMaxSizeResponsePDU(),
        event.getStateReference(),
        new StatusInformation());
  }
}

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

PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();

代码示例来源:origin: org.apache.camel/camel-snmp

@Override
protected void doStart() throws Exception {
  super.doStart();
  this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
  LOG.debug("targetAddress: {}", targetAddress);
  this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
  SecurityModels.getInstance().addSecurityModel(this.usm);
  
  // setting up target
  this.target = new CommunityTarget();
  this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
  this.target.setAddress(this.targetAddress);
  this.target.setRetries(this.endpoint.getRetries());
  this.target.setTimeout(this.endpoint.getTimeout());
  this.target.setVersion(this.endpoint.getSnmpVersion());
  this.pdu = new PDU();
  for (OID oid : this.endpoint.getOids()) {
    this.pdu.add(new VariableBinding(oid));
  }
  this.pdu.setErrorIndex(0);
  this.pdu.setErrorStatus(0);
  this.pdu.setMaxRepetitions(0);
  this.pdu.setType(PDU.GET);
  
}

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

private void sendUnknownPDUHandlersReport(CommandResponderEvent command) {
 logger.info("No PDU handler found for request "+command);
 CounterEvent counter =
   new CounterEvent(this, SnmpConstants.snmpUnknownPDUHandlers);
 fireIncrementCounter(counter);
 if ((command.getMessageProcessingModel() == MessageProcessingModel.MPv3) &&
   (command.getPDU() instanceof ScopedPDU)) {
  ScopedPDU request = (ScopedPDU) command.getPDU();
  ScopedPDU report = new ScopedPDU();
  report.setContextEngineID(request.getContextEngineID());
  report.setContextName(request.getContextName());
  report.setType(PDU.REPORT);
  report.add(new VariableBinding(counter.getOid(),
                  counter.getCurrentValue()));
  sendResponse(command, report);
 }
 else {
  PDU resp = (PDU) command.getPDU().clone();
  resp.setErrorStatus(PDU.genErr);
  sendResponse(command, resp);
 }
}

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

private void sendUnknownPDUHandlersReport(CommandResponderEvent command) {
  logger.info("No PDU handler found for request " + command);
  CounterEvent counter =
      new CounterEvent(this, SnmpConstants.snmpUnknownPDUHandlers);
  fireIncrementCounter(counter);
  if ((command.getMessageProcessingModel() == MessageProcessingModel.MPv3) &&
      (command.getPDU() instanceof ScopedPDU)) {
    ScopedPDU request = (ScopedPDU) command.getPDU();
    ScopedPDU report = new ScopedPDU();
    report.setContextEngineID(request.getContextEngineID());
    report.setContextName(request.getContextName());
    report.setType(PDU.REPORT);
    report.add(new VariableBinding(counter.getOid(),
        counter.getCurrentValue()));
    sendResponse(command, report);
  } else {
    PDU resp = (PDU) command.getPDU().clone();
    resp.setErrorStatus(PDU.genErr);
    sendResponse(command, resp);
  }
}

相关文章