当前位置: 首页>>代码示例>>Java>>正文


Java PDU.noError方法代码示例

本文整理汇总了Java中org.snmp4j.PDU.noError方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.noError方法的具体用法?Java PDU.noError怎么用?Java PDU.noError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.snmp4j.PDU的用法示例。


在下文中一共展示了PDU.noError方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
    Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
    snmp.listen();

    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(new UdpAddress("23.23.52.11/161"));
    target.setTimeout(3000);    //3s
    target.setRetries(1);

    PDU pdu = new PDU();
    pdu.setType(PDU.GETBULK);
    pdu.setMaxRepetitions(1); 
    pdu.setNonRepeaters(0);
    VariableBinding[] array = {new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.7")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.3.1.1.10")),
                               new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.19"))};
    pdu.addAll(array);

    //pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.2000.1.2.5.1.3"))); 

    ResponseEvent responseEvent = snmp.send(pdu, target);
    PDU response = responseEvent.getResponse();

    if (response == null) {
	    System.out.println("TimeOut...");
    } else {
	    if (response.getErrorStatus() == PDU.noError) {
               Vector<? extends VariableBinding> vbs = response.getVariableBindings();
               for (VariableBinding vb : vbs) {
                   System.out.println(vb.getVariable().toString());
	        }
	    } else {
	        System.out.println("Error:" + response.getErrorStatusText());
	    }
    }
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:40,代码来源:testSNMPGetBulk.java

示例2: snmpGet

import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
 * Triggers snmpget command.
 * 
 * @param oid oid
 * @param target {@link org.snmp4j.Target}
 * @return response from SNMP server
 * @throws IllegalStateException
 */
public String snmpGet(OID oid, Target target) {
	validateSnmpClient();
	
	final ResponseEvent responseEvent = sendSnmpGetRequest(oid, target);
	
	validateResponseEvent(responseEvent);
	validateResponseFromResponseEvent(responseEvent);
	if (responseEvent.getResponse().getErrorStatus() == PDU.noError) {
		return responseEvent.getResponse().getVariableBindings().toString();
	} else {
		throw new IllegalStateException(prepareErrorExceptionForGet(responseEvent.getResponse()));
	}
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:22,代码来源:SNMPWrapper.java

示例3: process

import org.snmp4j.PDU; //导入方法依赖的package包/类
@Override
public Status process() throws EventDeliveryException {
    Status status = null;
    counterGroup = new CounterGroup();

    try {
        // This try clause includes whatever Channel operations you want to do
        Event event = new SimpleEvent(); 
        Map <String, String> headers = new HashMap<String, String>();
        StringBuilder stringBuilder = new StringBuilder();

        ResponseEvent responseEvent = snmp.send(pdu, target);
        PDU response = responseEvent.getResponse();

        DateFormat dateFormat = new SimpleDateFormat("MM dd HH:mm:ss yyyy");
        Date date = new Date();

        stringBuilder.append(date + ",");
        stringBuilder.append(bindAddress + ",");

        if (response == null) {
            logger.info("TimeOut...");
        } else {
            if (response.getErrorStatus() == PDU.noError) {
                Vector<? extends VariableBinding> vbs = response.getVariableBindings();
                for (VariableBinding vb : vbs) {
                    //System.out.println(vb.getVariable().toString());
                    stringBuilder.append(vb.getVariable().toString() + ",");
                                       }
            } else {
                logger.info("Error:" + response.getErrorStatusText());
            }
        }

        String messageString = stringBuilder.toString();
        // trick: remove the last comma
        messageString = messageString.replaceAll(",$", "");
        byte[] message = messageString.getBytes();

        headers.put("timestamp", String.valueOf(System.currentTimeMillis()));
        logger.info("Message: {}", messageString);
        event.setBody(message);
        event.setHeaders(headers);

        // Store the Event into this Source's associated Channel(s)
        getChannelProcessor().processEvent(event);
        counterGroup.incrementAndGet("events.success");

        Thread.sleep(delayQuery*1000);
        status = Status.READY;

    } catch (ChannelException|IOException|InterruptedException ex) {
        counterGroup.incrementAndGet("events.dropped");
        logger.error("Error writting to channel", ex);
        // Log exception, handle individual exceptions as needed
        status = Status.BACKOFF;

        // re-throw all Errors
        //if (t instanceof Error) {
        //    throw (Error);
        //}
    }
    return status;
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:65,代码来源:SNMPQuerySource.java

示例4: main

import org.snmp4j.PDU; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
  System.out.println("SNMP GET-NEXT Simple Request");

  // Create TransportMapping and Listen
  TransportMapping transport = new DefaultUdpTransportMapping();
  transport.listen();

  // Create Target Address object
  CommunityTarget comtarget = new CommunityTarget();
  comtarget.setCommunity(new OctetString(community));
  comtarget.setVersion(snmpVersion);
  comtarget.setAddress(new UdpAddress(ipAddress + "/" + port));
  comtarget.setRetries(2);
  comtarget.setTimeout(1000);

  // Create the PDU object
  PDU pdu = new PDU();
  pdu.add(new VariableBinding(new OID(oidValue))); 
  pdu.setRequestID(new Integer32(1));
  pdu.setType(PDU.GETNEXT);
  
  // Create Snmp object for sending data to Agent
  Snmp snmp = new Snmp(transport);

  System.out.println("Sending GetNext Request to Agent ...");
  
  ResponseEvent response = snmp.getNext(pdu, comtarget);

  // Process Agent Response
  if (response != null)
  {
    System.out.println("\nResponse:\nGot GetNext Response from Agent...");
    PDU responsePDU = response.getResponse();

    if (responsePDU != null)
    {
      int errorStatus = responsePDU.getErrorStatus();
      int errorIndex = responsePDU.getErrorIndex();
      String errorStatusText = responsePDU.getErrorStatusText();

      if (errorStatus == PDU.noError)
      {
        System.out.println("Snmp GetNext Response for sysObjectID = " + responsePDU.getVariableBindings());
      }
      else
      {
        System.out.println("Error: Request Failed");
        System.out.println("Error Status = " + errorStatus);
        System.out.println("Error Index = " + errorIndex);
        System.out.println("Error Status Text = " + errorStatusText);
      }
    }
    else
    {
      System.out.println("Error: GetNextResponse PDU is null");
    }
  }
  else
  {
    System.out.println("Error: Agent Timeout... ");
  }
  snmp.close();
}
 
开发者ID:javiroman,项目名称:flume-snmp-source,代码行数:65,代码来源:testSNMPQuery.java


注:本文中的org.snmp4j.PDU.noError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。