Package org.snmp4j

Examples of org.snmp4j.Snmp$ReportHandler


          }
        }
      }

      UdpAddress udpAddr = new UdpAddress(UdpAddress.ANY_IPADDRESS, 0);
      Snmp snmp = new Snmp(new DefaultUdpTransportMapping(udpAddr));
      /* the snmp connection is open... add a seprate try/catch so we can make sure we close it */
      try {
        if ((version.equals("1")) || (version.equals("2c"))) {
          target = getCommunityTarget(targetAddress, Integer.parseInt(timeout), community, version);
        }
        else {
            OID auth = null;
            OID priv = null;

            if (auth_protocol != null) {
              if (auth_protocol.equals("MD5")) {
                auth = AuthMD5.ID;
              }
              else if (auth_protocol.equals("SHA")) {
                auth = AuthSHA.ID;
              }
            }

            if (privacy_protocol != null) {
              if (privacy_protocol.equals("AES128")) {
                priv = PrivAES128.ID;
              }
              else if (privacy_protocol.equals("AES192")) {
                priv = PrivAES192.ID;
              }
              else if (privacy_protocol.equals("AES256")) {
                priv = PrivAES256.ID;
              }
              else if (privacy_protocol.equals("DES")) {
                priv = PrivDES.ID;
              }
            }

            SecurityProtocols sec = SecurityProtocols.getInstance();
            ((MPv3)snmp.getMessageProcessingModel(MPv3.ID)).setLocalEngineID(localEngineID.getValue());
            USM usm = new USM(sec, localEngineID, 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            UsmUser user = new UsmUser(new OctetString(security_name),
                                           auth,
                                           new OctetString(auth_passphrase),
                                           priv,
                                           new OctetString(privacy_passphrase));
            snmp.getUSM().addUser(user);
            SecurityModels.getInstance().addSecurityModel(new TSM(localEngineID, false));
            target = getUserTarget(targetAddress, Integer.parseInt(timeout), security_level, security_name, security_engine);
        }
        snmp.listen();
        Iterator it = oids.entrySet().iterator();
        Exception ret = null;
        if (walk_base != null) {
          ret = walkHard(snmp, target, context_engine, context_name, walk_base, rr);
        }
        if (send_separate_queries == true) {
          ret = processIndividually(snmp, target, context_engine, context_name, it, oid_hashmap, rr);
        }
        else {
          ret = processAll(snmp, target, context_engine, context_name, it, oid_hashmap, rr);
        }
        if (ret != null) {
          throw(ret);
        }
        /* Go through remaining named values, return blank strings */
        blankMissingValues(oid_hashmap, rr);
      }
      catch (Exception e) {
        String error_msg = e.getMessage();
        if (error_msg != null) {
          rr.set("jezebel_status", error_msg);
        }
      }
      snmp.close();
    }
    catch(Exception e){
      String error_msg = e.getMessage();
      if (error_msg != null) {
        rr.set("jezebel_status", error_msg);
View Full Code Here


        _target = new CommunityTarget();
        _target.setCommunity(new OctetString(community));
        _target.setVersion(SnmpConstants.version2c);
        _target.setAddress(new UdpAddress(address));
        try {
            _snmp = new Snmp(new DefaultUdpTransportMapping());
        } catch (IOException e) {
            _snmp = null;
            throw new CloudRuntimeException(" Error in crearting snmp object, " + e.getMessage());
        }
    }
View Full Code Here

            transport = new DefaultUdpTransportMapping();
        }

        // Could save some CPU cycles:
        // transport.setAsyncMsgProcessingSupported(false);
        Snmp snmp = new Snmp(transport);

        if (version == SnmpConstants.version3) {
            USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            addUsmUser(snmp);
View Full Code Here

            return target;
        }
    }

    public PDU send() throws IOException {
        Snmp snmp = createSnmpSession();
        try {
            this.target = createTarget();
            target.setVersion(version);
            target.setAddress(address);
            target.setRetries(retries);
            target.setTimeout(timeout);
            snmp.listen();

            PDU request = createPDU(target);
            if (request.getType() == PDU.GETBULK) {
                request.setMaxRepetitions(maxRepetitions);
                request.setNonRepeaters(nonRepeaters);
            }

            for (Object vb : vbs) {
                request.add((VariableBinding) vb);
            }

            PDU response = null;
            ResponseEvent responseEvent;
            long startTime = System.currentTimeMillis();
            responseEvent = snmp.send(request, target);
            if (responseEvent != null) {
                response = responseEvent.getResponse();
                if (log.isDebugEnabled())
                    log.debug("Received response after " + (System.currentTimeMillis() - startTime) + " millis");
            }
            return response;
        } finally {
            snmp.close();
        }
    }
View Full Code Here

    @BeforeMethod
    public void setUp() throws Exception {
        receivedTraps = new ConcurrentLinkedQueue<PDU>();

        snmp = new Snmp(new DefaultUdpTransportMapping());
        Address targetAddress = new UdpAddress(getTestPort());
        boolean installedTrapListener = snmp.addNotificationListener(targetAddress, new CommandResponder() {
            @Override
            public void processPdu(CommandResponderEvent event) {
                receivedTraps.offer(event.getPDU());
View Full Code Here

        super.before();
        port = configuration.getSimple("port").getIntegerValue();
        try {
            address = InetAddress.getLocalHost();
            peer = new DefaultUdpTransportMapping(); //new UdpAddress(address, getPort()));
            snmp = new Snmp(peer);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

        // TODO: check if the engine is already alive
        try {
            UdpAddress targetAddress = new UdpAddress(port);
            // TransportMapping transport = new DefaultUdpTransportMapping(targetAddress);
            snmp = new Snmp(new DefaultUdpTransportMapping());
            snmpTrapEventPoller = new SnmpTrapEventPoller(severityOid);
            eventContext.registerEventPoller(snmpTrapEventPoller, pollInterval);
            // TODO set up the community here
            if (!snmp.addNotificationListener(targetAddress, snmpTrapEventPoller))
                throw new IOException("cannot attach to " + targetAddress);
View Full Code Here

    private Snmp initSession() throws SNMPException {
        try {
            InetAddress host = InetAddress.getByName(ANY_LOCAL_ADDRESS);
            int port = ANY_FREE_PORT;
            UdpAddress addr = new UdpAddress(host, port);
            session = new Snmp(new DefaultUdpTransportMapping(addr));
            session.listen();
        } catch (IOException e) {
            throw new SNMPException("Failed to initialize SNMP session.", e);
        }
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 " + 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

TOP

Related Classes of org.snmp4j.Snmp$ReportHandler

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.