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

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

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

PDU.getTypeString介绍

[英]Gets a string representation of the supplied PDU type.
[中]获取提供的PDU类型的字符串表示形式。

代码示例

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

private void checkOptions() {
 if ((operation == WALK) &&
   ((pduType != PDU.GETBULK) && (pduType != PDU.GETNEXT))) {
  throw new IllegalArgumentException(
    "Walk operation is not supported for PDU type: "+
    PDU.getTypeString(pduType));
 }
 else if ((operation == WALK) && (vbs.size() != 1)) {
  throw new IllegalArgumentException(
    "There must be exactly one OID supplied for walk operations");
 }
 if ((pduType == PDU.V1TRAP) && (version != SnmpConstants.version1)) {
  throw new IllegalArgumentException(
    "V1TRAP PDU type is only available for SNMP version 1");
 }
}

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

private void checkOptions() {
 if ((operation == WALK) &&
   ((pduType != PDU.GETBULK) && (pduType != PDU.GETNEXT))) {
  throw new IllegalArgumentException(
    "Walk operation is not supported for PDU type: "+
    PDU.getTypeString(pduType));
 }
 else if ((operation == WALK) && (vbs.size() != 1)) {
  throw new IllegalArgumentException(
    "There must be exactly one OID supplied for walk operations");
 }
 if ((pduType == PDU.V1TRAP) && (version != SnmpConstants.version1)) {
  throw new IllegalArgumentException(
    "V1TRAP PDU type is only available for SNMP version 1");
 }
}

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

/**
 * Constructs a new trap information instance that contains the sending
 * agent, the community string, and the Protocol Data Unit.
 * 
 * @param agent
 *            The sending agent's address
 * @param community
 *            The community string from the SNMP packet.
 * @param pdu
 *            The encapsulated Protocol Data Unit.
 */
public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu) {
  super(agent, community);
  m_pdu = pdu;
  m_pduTypeString = PDU.getTypeString(m_pdu.getType());
}

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

/**
 * Constructs a new trap information instance that contains the sending
 * agent, the community string, and the Protocol Data Unit.
 * 
 * @param agent
 *            The sending agent's address
 * @param community
 *            The community string from the SNMP packet.
 * @param pdu
 *            The encapsulated Protocol Data Unit.
 * @param trapProcessor The trap processor used to process the trap data
 * 
 */
public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu, TrapProcessor trapProcessor) {
  super(agent, community, trapProcessor);
  m_pdu = pdu;
  m_pduTypeString = PDU.getTypeString(m_pdu.getType());
}

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

/**
 * Constructs a new trap information instance that contains the sending
 * agent, the community string, and the Protocol Data Unit.
 * 
 * @param agent
 *            The sending agent's address
 * @param community
 *            The community string from the SNMP packet.
 * @param pdu
 *            The encapsulated Protocol Data Unit.
 */
public Snmp4JV2TrapInformation(InetAddress agent, String community, PDU pdu) {
  super(agent, community);
  m_pdu = pdu;
  m_pduTypeString = PDU.getTypeString(m_pdu.getType());
}

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

/**
 * Returns a string representation of the object.
 *
 * @return a string representation of the object.
 */
public String toString() {
  StringBuilder buf = new StringBuilder();
  buf.append(getTypeString(type));
  buf.append("[requestID=");
  buf.append(requestID);
  buf.append(", errorStatus=");
  buf.append(getErrorStatusText()).append("(").append(errorStatus).append(")");
  buf.append(", errorIndex=");
  buf.append(errorIndex);
  buf.append(", VBS[");
  for (int i = 0; i < variableBindings.size(); i++) {
    buf.append(variableBindings.get(i));
    if (i + 1 < variableBindings.size()) {
      buf.append("; ");
    }
  }
  buf.append("]]");
  return buf.toString();
}

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

/**
 * Returns a string representation of the object.
 *
 * @return a string representation of the object.
 */
public String toString() {
 StringBuffer buf = new StringBuffer();
 buf.append(getTypeString(type));
 buf.append("[requestID=");
 buf.append(requestID);
 buf.append(", errorStatus=");
 buf.append(getErrorStatusText()+"("+errorStatus+")");
 buf.append(", errorIndex=");
 buf.append(errorIndex);
 buf.append(", VBS[");
 for (int i=0; i<variableBindings.size(); i++) {
  buf.append(variableBindings.get(i));
  if (i+1 < variableBindings.size()) {
   buf.append("; ");
  }
 }
 buf.append("]]");
 return buf.toString();
}

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

/**
 * Returns a string representation of the object.
 *
 * @return a string representation of the object.
 */
public String toString() {
 StringBuilder buf = new StringBuilder();
 buf.append(getTypeString(type));
 buf.append("[requestID=");
 buf.append(requestID);
 buf.append(", errorStatus=");
 buf.append(getErrorStatusText()).append("(").append(errorStatus).append(")");
 buf.append(", errorIndex=");
 buf.append(errorIndex);
 buf.append(", VBS[");
 for (int i=0; i<variableBindings.size(); i++) {
  buf.append(variableBindings.get(i));
  if (i+1 < variableBindings.size()) {
   buf.append("; ");
  }
 }
 buf.append("]]");
 return buf.toString();
}

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

@Override
public void processPdu(CommandResponderEvent e) {
  PDU pdu = e.getPDU();
  if (pdu != null){
    
    if (pdu instanceof PDUv1){
      processPDUv1((PDUv1)pdu);
    }
    else if (pdu instanceof ScopedPDU) {
      processScopedPDU((ScopedPDU)pdu);
    } 
    else if (pdu instanceof PDU){
      processPDUv2c(pdu);
    }
    else {
      log.warn("Unknown PDU type: " + PDU.getTypeString(pdu.getType()));
    }
    
  }
}

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

@Override
public void processPdu(CommandResponderEvent e) {
  PDU pdu = e.getPDU();
  if (pdu != null){
    
    if (pdu instanceof PDUv1){
      processPDUv1((PDUv1)pdu);
    }
    else if (pdu instanceof ScopedPDU) {
      processScopedPDU((ScopedPDU)pdu);
    } 
    else if (pdu instanceof PDU){
      processPDUv2c(pdu);
    }
    else {
      log.warn("Unknown PDU type: " + PDU.getTypeString(pdu.getType()));
    }
    
  }
}

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

log.debug("Received Snmp request of type: "+PDU.getTypeString(pdu.getType()));
default:
  log.warn("Cannot process request PDU of type: " + 
      PDU.getTypeString(type) + "unsupported");
  return;

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

log.debug("Received Snmp request of type: "+PDU.getTypeString(pdu.getType()));
default:
  log.warn("Cannot process request PDU of type: " + 
      PDU.getTypeString(type) + "unsupported");
  return;

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

(snmpRequest.getPduType() == PDU.V1TRAP) ||
 (snmpRequest.getPduType() == PDU.RESPONSE)) {
System.out.println(PDU.getTypeString(snmpRequest.getPduType()) +
          " sent successfully");

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

(pduType == PDU.V1TRAP) ||
    (pduType == PDU.RESPONSE)) {
  out.println(PDU.getTypeString(pduType) +
      " sent successfully");
} else if (response == null) {

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

protected void validate() {
  int pduType = getPdu().getType();
  if (pduType != PDU.TRAP && pduType != PDU.INFORM) {
    throw new IllegalArgumentException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));

代码示例来源: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.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: OpenNMS/opennms

int pduType = getPdu().getType();
if (pduType != PDU.TRAP && pduType != PDU.INFORM) {
  throw new SnmpException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));

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

int pduType = getPdu().getType();
if (pduType != PDU.TRAP && pduType != PDU.INFORM) {
  throw new SnmpException("Received not SNMPv2 Trap|Inform from host " + getTrapAddress() + " PDU Type = " + PDU.getTypeString(getPdu().getType()));

代码示例来源: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);
  }
}

相关文章