Package org.snmp4j.event

Examples of org.snmp4j.event.ResponseEvent


     * @param OIDString  OID of variable to retrieve
     * @return           SNMP4J variable containing retrieved value
     */
    protected Variable getMIBValue(String OIDString, SNMPType valueType) throws SNMPException, SNMPTypeException {
        PDU pdu;
        ResponseEvent response;
        Variable var;
       
        try {
            pdu = new PDU();
            if ( OIDString == null ) {
                logger.debug("OID string not set for SNMP GET of " + address.getHostAddress());
                throw new SNMPTypeException("OID string not set for SNMP GET of " + address.getHostAddress());
            }
            pdu.add(new VariableBinding(new OID(OIDString)));
            logger.debug("SNMP GET of " + address.getHostAddress() + " :: " + OIDString);
            response = snmp.get(pdu, target);
            if ( response.getError() != null ) {
                logger.error("Error while issuing SNMP GET for " +
                        address.getHostAddress() + " :: " + OIDString);
                throw new SNMPException("Error while issuing SNMP GET for " +
                        address.getHostAddress() + " :: " + OIDString, response.getError());
            }
            if ( response.getResponse() == null ) {
                logger.warn("SNMP GET timeout for " + address.getHostAddress() + " :: " + OIDString);
                throw (new SNMPException("SNMP GET timeout for " + address.getHostAddress() + " :: " + OIDString));
            }
            var = response.getResponse().get(0).getVariable();
            logger.debug("SNMP GET result: " + address.getHostAddress() + " :: " + OIDString + " = " + var);
            if ( var instanceof org.snmp4j.smi.Null ) {
                logger.warn("OID not found in MIB for SNMP GET for " + address.getHostAddress() + " :: " + OIDString);
                throw new SNMPException("OID not found in MIB for SNMP GET for " + address.getHostAddress() + " :: " + OIDString);
            }
View Full Code Here


        return address.getInetAddress();
    }
   
    public LinkedList getNextMIBValue(String OIDString, SNMPType valueType, String scope) throws SNMPException, SNMPScopeException {
        PDU pdu;
        ResponseEvent response;
        String nextOID;
        Variable nextVariable;
        Object nextValue;
        LinkedList returnPair;
       
        try {
            pdu = new PDU();
            pdu.add(new VariableBinding(new OID(OIDString)));
            logger.debug("SNMP GETNEXT of " + address.getHostAddress() + " :: " + OIDString);
            response = snmp.getNext(pdu, target);
           
            if ( response.getError() != null ) {
                logger.error("Error while issuing SNMP GETNEXT for " +
                        address.getHostAddress() + " :: " + OIDString);
                throw new SNMPException("Error while issuing SNMP GETNEXT for " +
                        address.getHostAddress() + " :: " + OIDString, response.getError());
            }
            if ( response.getResponse() == null ) {
                logger.warn("SNMP GET timeout for " + address.getHostAddress() + " :: " + OIDString);
                throw (new SNMPException("SNMP GETNEXT timeout for " + address.getHostAddress() + " :: " + OIDString));
            }
           
            returnPair = new LinkedList();
            nextOID = response.getResponse().get(0).getOid().toString();
           
            // Scope check
            if ( scope != null && ! nextOID.matches(scope + ".*")) {
                logger.debug("OID " + nextOID + " not under scope " + scope + " in MIB for SNMP GETNEXT on " + address.getHostAddress() + " :: " + OIDString);
                throw new SNMPScopeException("OID " + nextOID + " not under scope " + scope + " in MIB on SNMP GETNEXT for " + address.getHostAddress() + " :: " + OIDString);
            }
           
            returnPair.add(nextOID);
            nextVariable = response.getResponse().get(0).getVariable();
           
            if ( nextVariable instanceof org.snmp4j.smi.Null ) {
                logger.warn("OID not found in MIB for SNMP GETNEXT on " + address.getHostAddress() + " :: " + OIDString);
                throw new SNMPException("OID not found in MIB for SNMP GETNEXT on " + address.getHostAddress() + " :: " + OIDString);
            }
View Full Code Here

     * @param value      SNMP4J variable containing the value to set
     * @return           value contained in the response PDU
     */
    public Variable setMIBValue(String OIDString, Variable value) throws SNMPException {
        PDU pdu;
        ResponseEvent response;
        Variable returnValue;
       
        pdu = new PDU();
        pdu.add(new VariableBinding(new OID(OIDString), value));
        logger.debug("SNMP SET of " + address.getHostAddress() + " :: " + OIDString + " to " + value);
        response = snmp.set(pdu, target);
       
        if ( response.getError() != null ) {
            logger.error("Error while issuing SNMP SET for " +
                    address.getHostAddress() + " :: " + OIDString);
            throw new SNMPException("Error while issuing SNMP GETNEXT for " +
                    address.getHostAddress() + " :: " + OIDString, response.getError());
        }
        if ( response.getResponse() == null ) {
            logger.warn("SNMP SET timeout for " + address.getHostAddress() + " :: " + OIDString);
            throw (new SNMPException("SNMP GET timeout for " + address.getHostAddress() + " :: " + OIDString));
        }
       
        returnValue = response.getResponse().get(0).getVariable();
        logger.debug("SNMP SET result: " + address.getHostAddress() + " :: " + OIDString + " = " + returnValue);
        return returnValue;
    }
View Full Code Here

          request.add(new VariableBinding(new OID(pairs.getValue().toString().substring(1))));
        }
        catch (Exception e) {
        }
      }
      ResponseEvent responseEvent = snmp.send(request, target);
      if (responseEvent != null) {
        response = responseEvent.getResponse();
        processResponse(response, oid_hashmap, rr);
      }
    }
    catch(Exception e) {
      return e;
View Full Code Here

          request.add(new VariableBinding(new OID(pairs.getValue().toString().substring(1))));
        }
        catch (Exception e) {
          continue;
        }
        ResponseEvent responseEvent = snmp.send(request, target);
        if (responseEvent != null) {
          response = responseEvent.getResponse();
          processResponse(response, oid_hashmap, rr);
        }
      }
    }
    catch(Exception e) {
View Full Code Here

            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 {
View Full Code Here

    }

    @NotNull
    private PDU sendRequest(PDU request, String mibName) throws SNMPException {
        String requestType = PDU.getTypeString(request.getType());
        ResponseEvent responseEvent;
        try {
            responseEvent = session.send(request, this.target);
        } catch (IOException e) {
            throw new SNMPException("Failed to send " + requestType + " request for [" + mibName + "]", e);
        }

        if (responseEvent == null) {
            throw new SNMPException("No response to " + requestType + " request for [" + mibName + "].");
        }

        PDU response = responseEvent.getResponse();
        if (response == null) {
            throw new SNMPTimeoutException(requestType + " request for [" + mibName + "] timed out.");
        }

        return response;
View Full Code Here

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

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

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

TOP

Related Classes of org.snmp4j.event.ResponseEvent

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.