Examples of ResponseEvent


Examples of org.snmp4j.event.ResponseEvent

public class MYSNMP {

    public String SNMP_GET(String ipAddress, int port, String strOID, String community) {
        String strResponse = "";
        ResponseEvent response;
        Snmp snmp;
        try {
            OctetString community1 = new OctetString(community);
            String host = ipAddress + "/" + port;
            Address tHost = new UdpAddress(host);
            TransportMapping transport = new DefaultUdpTransportMapping();
            transport.listen();
            CommunityTarget comtarget = new CommunityTarget();
            comtarget.setCommunity(community1);
            comtarget.setVersion(SnmpConstants.version1);
            comtarget.setAddress(tHost);
            comtarget.setRetries(2);
            comtarget.setTimeout(5000);
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID(strOID)));
            pdu.setType(PDU.GET);
            snmp = new Snmp(transport);
            response = snmp.get(pdu, comtarget);
            if (response != null) {
                if (response.getResponse().getErrorStatusText().equalsIgnoreCase("Success")) {
                    PDU pduresponse = response.getResponse();
                    strResponse = pduresponse.getVariableBindings().firstElement().toString();
                    if (strResponse.contains("=")) {
                        String strNewResponse[] = null;
                        int len = strResponse.indexOf("=");
                        strNewResponse = strResponse.split("=");
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

public class MYSNMP {

    public String SNMP_GET(String ipAddress, int port, String strOID, String community) {
        String strResponse = "";
        ResponseEvent response;
        Snmp snmp;
        try {
            OctetString community1 = new OctetString(community);
            String host = ipAddress + "/" + port;
            Address tHost = new UdpAddress(host);
            TransportMapping transport = new DefaultUdpTransportMapping();
            transport.listen();
            CommunityTarget comtarget = new CommunityTarget();
            comtarget.setCommunity(community1);
            comtarget.setVersion(SnmpConstants.version1);
            comtarget.setAddress(tHost);
            comtarget.setRetries(2);
            comtarget.setTimeout(5000);
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID(strOID)));
            pdu.setType(PDU.GET);
            snmp = new Snmp(transport);
            response = snmp.get(pdu, comtarget);
            if (response != null) {
                if (response.getResponse().getErrorStatusText().equalsIgnoreCase("Success")) {
                    PDU pduresponse = response.getResponse();
                    strResponse = pduresponse.getVariableBindings().firstElement().toString();
                    if (strResponse.contains("=")) {
                        String strNewResponse[] = null;
                        int len = strResponse.indexOf("=");
                        strNewResponse = strResponse.split("=");
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

   
    try {
      DefaultUdpTransportMapping udpTransportMap = new
        DefaultUdpTransportMapping();
      Snmp snmp = new Snmp(udpTransportMap);
      ResponseEvent response =  snmp.send(pdu, target);
      logger.debug("trap pdu: " + pdu);
      logger.trace("response: " + response);
     
      snmp.close();
    } catch (IOException e) {
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

      comtarget.setVersion(SnmpConstants.version1);
      comtarget.setAddress(targetaddress);
      comtarget.setRetries(2);
      comtarget.setTimeout(5000);
      PDU pdu = new PDU();
      ResponseEvent response;
      Snmp snmp;
      pdu.add(new VariableBinding(new OID(oid)));
      pdu.setType(PDU.GET);
      snmp = new Snmp(transport);
      response = snmp.get(pdu,comtarget);
      if(response != null) {
        String errorStatus =
          response.getResponse().getErrorStatusText();
        if(errorStatus.equalsIgnoreCase("Success")) {
          PDU pduresponse = response.getResponse();
          String str =
            pduresponse.getVariableBindings().firstElement().toString();
          if(str.contains("=")) {
            int len = str.indexOf("=");
            str=str.substring(len+1, str.length());
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

    if (operation == WALK) {
      walk(snmp, request, target);
      return null;
    }
    else {
      ResponseEvent responseEvent;
      long startTime = System.currentTimeMillis();
      responseEvent = snmp.send(request, target);
      if (responseEvent != null) {
        response = responseEvent.getResponse();
        System.out.println("Received response after "+
                           (System.currentTimeMillis()-startTime)+" millis");
      }
    }
    snmp.close();
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

    for (final SNMPv2<UdpAddress> v2Client : this.v2Clients) {

      final OID system = new OID("1.3.6.1.2.1.1");
      final OID ifTableRow1 = new OID("1.3.6.1.2.1.2.2.1.1");
      final OID ifTableRow2 = new OID("1.3.6.1.2.1.2.2.1.2");
      final ResponseEvent response = v2Client.getBulkSync(this.address,
          2, 1, system, ifTableRow1, ifTableRow2);
      final Map<OID, Variable> bindings = ResponseEvents
          .extractBindings(response);
      Assert.assertEquals(5, bindings.size());
      Assert.assertTrue(bindings.containsKey(new OID(system.toString()
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

  @Test
  public void testGetNextSync() throws IOException {

    for (final SNMP<UdpAddress> client : this.allClients) {

      final ResponseEvent response = client.getNextSync(this.address,
          new OID("1.3.6.1.2.1.1.1"));
      Assert.assertNotNull(response);
      Assert.assertTrue(ResponseEvents.extractBindings(response)
          .containsKey(SnmpConstants.sysDescr));
    }
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

  @Test
  public void testGetSync() throws IOException {

    for (final SNMP<UdpAddress> client : this.allClients) {

      final ResponseEvent response = client.getSync(this.address,
          SnmpConstants.sysDescr);
      Assert.assertNotNull(response);
      Assert.assertTrue(ResponseEvents.extractBindings(response)
          .containsKey(SnmpConstants.sysDescr));
    }
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

    for (final SNMP<UdpAddress> client : this.allClients) {

      final OID beforeSysDescr = new OID("1.3.6.1.2.1.1.1");
      final OID beforeSysLocation = new OID("1.3.6.1.2.1.1.6");
      final ResponseEvent response = client.getNextSync(this.address,
          beforeSysDescr, beforeSysLocation);
      Assert.assertNotNull(response);
      Assert.assertTrue(ResponseEvents.extractBindings(response)
          .containsKey(SnmpConstants.sysDescr));
      Assert.assertTrue(ResponseEvents.extractBindings(response)
View Full Code Here

Examples of org.snmp4j.event.ResponseEvent

  @Test
  public void testMultiGetSync() throws IOException {

    for (final SNMP<UdpAddress> client : this.allClients) {

      final ResponseEvent response = client.getSync(this.address,
          SnmpConstants.sysDescr, SnmpConstants.sysLocation);
      Assert.assertNotNull(response);
      Assert.assertTrue(ResponseEvents.extractBindings(response)
          .containsKey(SnmpConstants.sysDescr));
      Assert.assertTrue(ResponseEvents.extractBindings(response)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.