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

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

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

PDU.setType介绍

[英]Sets the PDU type.
[中]设置PDU类型。

代码示例

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

/**
 * Construct the PDU to perform the SNMP Get request and returns
 * the result in order to create the flow file.
 * @return {@link ResponseEvent}
 */
public ResponseEvent get() {
  try {
    PDU pdu = null;
    if(this.target.getVersion() == SnmpConstants.version3) {
      pdu = new ScopedPDU();
    } else {
      pdu = new PDU();
    }
    pdu.add(new VariableBinding(this.oid));
    pdu.setType(PDU.GET);
    return this.snmp.get(pdu, this.target);
  } catch (IOException e) {
    logger.error("Failed to get information from SNMP agent; " + this, e);
    throw new ProcessException(e);
  }
}

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

pdu.setType(PDU.SET);
try {
  ResponseEvent response = this.targetResource.set(pdu);

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {
   // Create PDU           
   PDU trap = new PDU();
   trap.setType(PDU.TRAP);

   OID oid = new OID("1.2.3.4.5");
   trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, oid));
   trap.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000))); // put your uptime here
   trap.add(new VariableBinding(SnmpConstants.sysDescr, new OctetString("System Description"))); 

   //Add Payload
   Variable var = new OctetString("some string");          
   trap.add(new VariableBinding(oid, var));          

   // Specify receiver
   Address targetaddress = new UdpAddress("10.101.21.32/162");
   CommunityTarget target = new CommunityTarget();
   target.setCommunity(new OctetString("public"));
   target.setVersion(SnmpConstants.version2c);
   target.setAddress(targetaddress);

   // Send
   Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
   snmp.send(trap, target, null, null);                      
}

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

protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) {
  m_strategy = strategy;
  m_pdu = pdu;
  m_pdu.setType(type);
}

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

protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) {
  m_strategy = strategy;
  m_pdu = pdu;
  m_pdu.setType(type);
}

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

protected Snmp4JV2TrapBuilder(Snmp4JStrategy strategy, PDU pdu, int type) {
  m_strategy = strategy;
  m_pdu = pdu;
  m_pdu.setType(type);
}

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

private PDU createPDU(SnmpTrapInfo snmpTrapInfo) {
  PDU trap = new PDU();
  trap.setType(PDU.TRAP);

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

protected PDU sendGetPDU(Row firstCacheRow, ResponseListener responseListener, PDU pdu) {
  try {
    session.send(pdu, target, firstCacheRow, responseListener);
    pdu = pduFactory.createPDU(target);
    pdu.setType(PDU.GET);
  } catch (IOException e) {
    logger.error(e);
  }
  return pdu;
}

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

private PDU buildDeletPDU(Object entry) throws IllegalArgumentException, IllegalAccessException, SnmpAnnotationException {
    PDU pdu = new PDU();
    pdu.setType(PDU.SET);
    pdu.add(buildDeleteVariableBinding(entry));
    return pdu;
  }
}

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

/**
 * Creates an SNMP4J PDU based on the SNMP4J version constants.
 * A v3 request requires a ScopedPDU.
 * 
 * @param type
 * @return
 */
public PDU createPdu(int type) {
  PDU pdu = getVersion() == SnmpConstants.version3 ? new ScopedPDU() : new PDU();
  pdu.setType(type);
  return pdu;
}

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

public PDU buildGetPDU(Class scalarClass, String[] fields) throws SecurityException, NoSuchFieldException {
  PDU pdu = new PDU();
  pdu.setType(PDU.GET);
  for (String fn : fields) {
    Field field = scalarClass.getDeclaredField(fn);
    MibObjectType mib = field.getAnnotation(MibObjectType.class);
    pdu.add(new VariableBinding(new OID(mib.oid())));
  }
  return pdu;
}

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

public SnmpUriResponse updateByValue(URI url, List<Variable> values) throws UnknownHostException {
 SnmpUriResponse response;
 Request request = createSnmpRequest(url);
 PDU pdu = request.getPdu();
 pdu.setType(PDU.SET);
 OID[] oids = request.getOIDs();
 for (int i=0; i<oids.length && i<values.size(); i++) {
  pdu.add(new VariableBinding(oids[i], values.get(i)));
 }
 response = sendSnmpRequest(request, pdu);
 return response;
}

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

public SnmpUriResponse updateByValue(URI url, List<Variable> values) throws UnknownHostException {
 SnmpUriResponse response;
 Request request = createSnmpRequest(url);
 PDU pdu = request.getPdu();
 pdu.setType(PDU.SET);
 OID[] oids = request.getOIDs();
 for (int i=0; i<oids.length && i<values.size(); i++) {
  pdu.add(new VariableBinding(oids[i], values.get(i)));
 }
 response = sendSnmpRequest(request, pdu);
 return response;
}

代码示例来源:origin: griddynamics/jagger

public ResponseEvent get(List<OID> oids) throws IOException {
  PDU pdu = new PDU();
  for (OID oid : oids) {
    pdu.add(new VariableBinding(oid));
  }
  pdu.setType(PDU.GET);
  ResponseEvent event = snmp.send(pdu, getTarget(), null);
  if(event != null) {
    return event;
  }
  throw new RuntimeException("GET timed out");
}

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

public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException {
 SnmpUriResponse response;
 Request request = createSnmpRequest(url);
 PDU pdu = request.getPdu();
 pdu.setType(pduType);
 for (VariableBinding vb : values) {
  pdu.add(vb);
 }
 response = sendSnmpRequest(request, pdu);
 return response;
}

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

public SnmpUriResponse sendByBinding(URI url, List<VariableBinding> values, int pduType) throws UnknownHostException {
 SnmpUriResponse response;
 Request request = createSnmpRequest(url);
 PDU pdu = request.getPdu();
 pdu.setType(pduType);
 for (VariableBinding vb : values) {
  pdu.add(vb);
 }
 response = sendSnmpRequest(request, pdu);
 return response;
}

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

@Override
public void poll() throws Exception {
  this.pdu.clear();
  this.pdu.setType(PDU.GET);
  // prepare the request items
  for (OID oid : oids) {
    this.pdu.add(new VariableBinding(oid));
  }
  // send the request
  snmp.send(pdu, target, null, this);
}

代码示例来源: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: net.itransformers.snmp2xml4j/snmptoolkit

private VariableBinding getSingleVariable(OID oid) throws IOException {
  PDU pdu = this.pduFactory.createPDU(getTarget());
  pdu.setType(PDU.GETNEXT);
  pdu.add(new VariableBinding(oid));
  ResponseEvent responseEvent = snmp.send(pdu, getTarget());
  PDU responsePDU = null;
  if (responseEvent != null) responsePDU = responseEvent.getResponse();
  VariableBinding vb = null;
  if (responsePDU != null) vb = responsePDU.get(0);
  return vb;
}

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

相关文章