org.snmp4j.Snmp.get()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(297)

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

Snmp.get介绍

[英]Sends a GET request to a target. This method sets the PDU's type to PDU#GET and then sends a synchronous request to the supplied target.
[中]向目标发送GET请求。此方法将PDU的类型设置为PDU#GET,然后向提供的目标发送同步请求。

代码示例

代码示例来源: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: com.rogueai/snmp2bean

public ResponseEvent get(PDU pdu, Target target) {
  try {
    return snmp.get(pdu, target);
  } catch (IOException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: usdot-jpo-ode/jpo-ode

/**
* Sends a SET-type PDU to the target specified by the constructor.
* 
* @param pdu
*           The message content to be sent to the target
* @return ResponseEvent
* @throws IOException
*/
public ResponseEvent get(PDU pdu, Snmp snmpob, UserTarget targetob, Boolean keepOpen) throws IOException {
 // Ensure the object has been instantiated
 if (!ready) {
   throw new IOException("Tried to send PDU before SNMP sending service is ready.");
 }
 // Start listening on UDP
 if (!listening) {
   startListen();
 }
 // Try to send the SNMP request (synchronously)
 ResponseEvent responseEvent = null;
 try {
   responseEvent = snmpob.get(pdu, targetob);
   if (!keepOpen) {
    snmpob.close();
   }
 } catch (IOException e) {
   throw new IOException("Failed to send SNMP request: " + e);
 }
 return responseEvent;
}

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

/**
 * 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: org.opendaylight.cardinal/cardinal-impl

pdu.setType(PDU.GET);
snmp = new Snmp(transport);
response = snmp.get(pdu, comtarget);
if (response != null) {
  if (response.getResponse().getErrorStatusText().equalsIgnoreCase("Success")) {

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

pdu.add(new VariableBinding(levelOID));
pdu.add(new VariableBinding(effLevelOID));
response = snmp.get(pdu, target);
PDU respPDU = response.getResponse();
if ((respPDU != null) &&

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

pdu.add(new VariableBinding(levelOID));
pdu.add(new VariableBinding(effLevelOID));
response = snmp.get(pdu, target);
PDU respPDU = response.getResponse();
if ((respPDU != null) &&

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

pdu.add(new VariableBinding(levelOID));
pdu.add(new VariableBinding(effLevelOID));
response = snmp.get(pdu, target);
PDU respPDU = response.getResponse();
if ((respPDU != null) &&

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

public void testGetSysName() throws IOException {
  
  Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
  snmp.listen();
  
  Address addr = new UdpAddress(InetAddress.getLocalHost(), 9161);
  //Address addr = new UdpAddress(InetAddressUtils.addr("192.168.0.100"), 161);
  Target target = new CommunityTarget(addr, new OctetString("public"));
  target.setVersion(SnmpConstants.version1);
  target.setTimeout(3000);
  target.setRetries(3);
  
  PDUv1 getRequest = new PDUv1();
  getRequest.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));
  
  ResponseEvent e = snmp.get(getRequest, target);
  PDU response = e.getResponse();
  
  assertEquals(new OctetString("mockhost"), response.get(0).getVariable());
  
  
}

相关文章