Package org.snmp4j

Examples of org.snmp4j.Snmp$AsyncRequestKey


            this.transport = new DefaultUdpTransportMapping((UdpAddress)this.listenGenericAddress);
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(transport);
        this.snmp.addCommandResponder(this);
       
        // listen to the transport
        if (LOG.isDebugEnabled()) {
            LOG.debug("Starting trap consumer on " + endpoint.getAddress() + " using " + endpoint.getProtocol() + " protocol");
View Full Code Here


            this.transport = new DefaultUdpTransportMapping();
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(this.transport);
        this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        // setting up target
        target = new CommunityTarget();
View Full Code Here

            this.transport = new DefaultUdpTransportMapping((UdpAddress)this.listenGenericAddress);
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(transport);
        this.snmp.addCommandResponder(this);
       
        // listen to the transport
        if (LOG.isDebugEnabled()) {
            LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
View Full Code Here

            this.transport = new DefaultUdpTransportMapping();
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(this.transport);
        this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);

        // setting up target
        target = new CommunityTarget();
View Full Code Here

            this.transport = new DefaultUdpTransportMapping((UdpAddress)this.listenGenericAddress);
        } else {
            throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
        }

        this.snmp = new Snmp(transport);
        this.snmp.addCommandResponder(this);
       
        // listen to the transport
        if (LOG.isDebugEnabled()) {
            LOG.debug("Starting trap consumer on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
View Full Code Here

    pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
   
    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) {
      throw new SNMPException("Cannot send trap. IO exception: "
          + e.getMessage());
    }
  }
View Full Code Here

 
  public static void snmpSet(String address, String community,
      String oid, int value, int port) throws SNMPException {
    address = address + "/" + port;
    Address targetAddress = GenericAddress.parse(address);
    Snmp snmp;
   
    try {
      TransportMapping transport = new DefaultUdpTransportMapping();
      snmp = new Snmp(transport);
      CommunityTarget target = new CommunityTarget();
      target.setCommunity(new OctetString(community));
      target.setAddress(targetAddress);
      target.setRetries(0);
      target.setTimeout(200);
      target.setVersion(SnmpConstants.version2c);
      PDU pdu = new PDU();
      pdu.add(new VariableBinding(new OID(oid), new Integer32(value)));
      pdu.setType(PDU.SET);
      ResponseListener listener = new ResponseListener() {
        public void onResponse(ResponseEvent event) {
        // Always cancel async request when response has been received
        // otherwise a memory leak is created! Not canceling a request
        // immediately can be useful when sending a request to a broadcast
        // address.
          ((Snmp)event.getSource()).cancel(event.getRequest(), this);
        }
      };
      snmp.send(pdu, target, null, listener);
      snmp.close();
    }
    catch (IOException e) {
      String message = "No set snmp. IO exception: " + e.getMessage();
      logger.error(message);
      throw new SNMPException(message);
View Full Code Here

      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());
          }
          str = str.trim();
          ret = Integer.parseInt(str);
        }
      } else {
        snmp.close();
        String message = "Nessuna risposta dal sub agent. OID: " + oid +
          ", agent: " + address;
        logger.error("no response by agent. OID: " + oid +
          ", agent: " + address);
        throw new SNMPException(message);   
      }
      snmp.close();
     
    } catch(NumberFormatException e) {
      String message = "Il valore di ritorno no integer per OID: " + oid;
      logger.error("data is no a int cause, NumberFormatException " +
          e.getMessage());
View Full Code Here

      transport = new DefaultUdpTransportMapping((UdpAddress)listenAddress);
    }
    else {
      transport = new DefaultTcpTransportMapping((TcpAddress)listenAddress);
    }
    snmp = new Snmp(dispatcher, transport);
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());
    snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
    USM usm = new USM(SecurityProtocols.getInstance(),
                      new OctetString(MPv3.createLocalEngineID()), 0);
View Full Code Here

    Preconditions.checkState(retries >= 0, "Retries cannot be less than zero");
    Preconditions.checkState(timeout >= 0, "Timeout cannot be less than zero");

    this.transportMapping = Preconditions.checkNotNull(transportMapping);
    this.snmp = new Snmp(this.transportMapping);
    this.retries = retries;
    this.timeout = timeout;

    if (reportHandler != null) {
      this.snmp.setReportHandler(reportHandler);
View Full Code Here

TOP

Related Classes of org.snmp4j.Snmp$AsyncRequestKey

Copyright © 2018 www.massapicom. 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.