Search in sources :

Example 61 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpRequestHandler method makeResponsePacket.

/**
     * Here we make a response packet from a request packet.
     * We return null if there no response packet to sent.
     */
private DatagramPacket makeResponsePacket(DatagramPacket reqPacket) {
    DatagramPacket respPacket = null;
    // Transform the request packet into a request SnmpMessage
    //
    SnmpMessage reqMsg = new SnmpMessage();
    try {
        reqMsg.decodeMessage(reqPacket.getData(), reqPacket.getLength());
        reqMsg.address = reqPacket.getAddress();
        reqMsg.port = reqPacket.getPort();
    } catch (SnmpStatusException x) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponsePacket", "packet decoding failed", x);
        }
        reqMsg = null;
        ((SnmpAdaptorServer) adaptorServer).incSnmpInASNParseErrs(1);
    }
    // Make the response SnmpMessage if any
    //
    SnmpMessage respMsg = null;
    if (reqMsg != null) {
        respMsg = makeResponseMessage(reqMsg);
    }
    //
    if (respMsg != null) {
        try {
            reqPacket.setLength(respMsg.encodeMessage(reqPacket.getData()));
            respPacket = reqPacket;
        } catch (SnmpTooBigException x) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponsePacket", "response message is too big");
            }
            try {
                respMsg = newTooBigMessage(reqMsg);
                reqPacket.setLength(respMsg.encodeMessage(reqPacket.getData()));
                respPacket = reqPacket;
            } catch (SnmpTooBigException xx) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponsePacket", "'too big' is 'too big' !!!");
                }
                adaptor.incSnmpSilentDrops(1);
            }
        }
    }
    return respPacket;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpMessage(com.sun.jmx.snmp.SnmpMessage) DatagramPacket(java.net.DatagramPacket) SnmpTooBigException(com.sun.jmx.snmp.SnmpTooBigException)

Example 62 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpSubRequestHandler method run.

public void run() {
    try {
        final ThreadContext oldContext = ThreadContext.push("SnmpUserData", data);
        try {
            switch(type) {
                case pduGetRequestPdu:
                    //
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:get operation on " + agent.getMibName());
                    }
                    agent.get(createMibRequest(varBind, version, data));
                    break;
                case pduGetNextRequestPdu:
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:getNext operation on " + agent.getMibName());
                    }
                    //#ifdef DEBUG
                    agent.getNext(createMibRequest(varBind, version, data));
                    break;
                case pduSetRequestPdu:
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:set operation on " + agent.getMibName());
                    }
                    agent.set(createMibRequest(varBind, version, data));
                    break;
                case pduWalkRequest:
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:check operation on " + agent.getMibName());
                    }
                    agent.check(createMibRequest(varBind, version, data));
                    break;
                default:
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:unknown operation (" + type + ") on " + agent.getMibName());
                    }
                    errorStatus = snmpRspGenErr;
                    errorIndex = 1;
                    break;
            }
        // end of switch
        } finally {
            ThreadContext.restore(oldContext);
        }
    } catch (SnmpStatusException x) {
        errorStatus = x.getStatus();
        errorIndex = x.getErrorIndex();
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:an Snmp error occurred during the operation", x);
        }
    } catch (Exception x) {
        errorStatus = SnmpDefinitions.snmpRspGenErr;
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:a generic error occurred during the operation", x);
        }
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "run", "[" + Thread.currentThread() + "]:operation completed");
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ThreadContext(com.sun.jmx.snmp.ThreadContext) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException)

Example 63 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpRequestHandler method newTooBigMessage.

private SnmpMessage newTooBigMessage(SnmpMessage reqMsg) throws SnmpTooBigException {
    SnmpMessage result = null;
    SnmpPduPacket reqPdu;
    try {
        reqPdu = (SnmpPduPacket) pduFactory.decodeSnmpPdu(reqMsg);
        if (reqPdu != null) {
            SnmpPduPacket respPdu = newTooBigPdu(reqPdu);
            result = (SnmpMessage) pduFactory.encodeSnmpPdu(respPdu, packet.getData().length);
        }
    } catch (SnmpStatusException x) {
        // been successfully called before.
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "newTooBigMessage", "Internal error", x);
        }
        throw new InternalError(x);
    }
    return result;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpMessage(com.sun.jmx.snmp.SnmpMessage) SnmpPduPacket(com.sun.jmx.snmp.SnmpPduPacket)

Example 64 with SnmpStatusException

use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.

the class SnmpAdaptorServer method sendTrapPdu.

/**
     * Send the specified trap PDU to every destinations from the ACL file.
     */
private void sendTrapPdu(SnmpPduPacket pdu) throws SnmpStatusException, IOException {
    // Make an SNMP message from the pdu
    //
    SnmpMessage msg = null;
    try {
        msg = (SnmpMessage) pduFactory.encodeSnmpPdu(pdu, bufferSize);
        if (msg == null) {
            throw new SnmpStatusException(SnmpDefinitions.snmpRspAuthorizationError);
        }
    } catch (SnmpTooBigException x) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent to anyone");
        }
        throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig);
    // FIXME: is the right exception to throw ?
    // We could simply forward SnmpTooBigException ?
    }
    // Now send the SNMP message to each destination
    //
    int sendingCount = 0;
    openTrapSocketIfNeeded();
    if (ipacl != null) {
        Enumeration<InetAddress> ed = ipacl.getTrapDestinations();
        while (ed.hasMoreElements()) {
            msg.address = ed.nextElement();
            Enumeration<String> ec = ipacl.getTrapCommunities(msg.address);
            while (ec.hasMoreElements()) {
                msg.community = ec.nextElement().getBytes();
                try {
                    sendTrapMessage(msg);
                    sendingCount++;
                } catch (SnmpTooBigException x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent to " + msg.address);
                    }
                }
            }
        }
    }
    //
    if (sendingCount == 0) {
        try {
            msg.address = InetAddress.getLocalHost();
            sendTrapMessage(msg);
        } catch (SnmpTooBigException x) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent.");
            }
        } catch (UnknownHostException e) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent.");
            }
        }
    }
    closeTrapSocketIfNeeded();
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) UnknownHostException(java.net.UnknownHostException) SnmpMessage(com.sun.jmx.snmp.SnmpMessage) SnmpTooBigException(com.sun.jmx.snmp.SnmpTooBigException) InetAddress(java.net.InetAddress)

Aggregations

SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)64 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)18 SnmpTableHandler (sun.management.snmp.util.SnmpTableHandler)18 SnmpOid (com.sun.jmx.snmp.SnmpOid)15 SnmpMessage (com.sun.jmx.snmp.SnmpMessage)5 SnmpTooBigException (com.sun.jmx.snmp.SnmpTooBigException)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)5 MBeanException (javax.management.MBeanException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ReflectionException (javax.management.ReflectionException)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 SnmpString (com.sun.jmx.snmp.SnmpString)4 BerDecoder (com.sun.jmx.snmp.BerDecoder)3 BerException (com.sun.jmx.snmp.BerException)3 Attribute (javax.management.Attribute)3 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)2 SnmpScopedPduPacket (com.sun.jmx.snmp.SnmpScopedPduPacket)2