Search in sources :

Example 16 with SnmpVarBind

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

the class SnmpMibOid method check.

/**
     * Generic handling of the <CODE>check</CODE> operation.
     *
     * <p> This method should be overridden in subclasses.
     * <p>
     *
     * @param req   The sub-request that must be handled by this node.
     *
     * @param depth The depth reached in the OID tree.
     *
     * @exception SnmpStatusException The default implementation (if not
     *            overridden) is to generate a SnmpStatusException.
     */
@Override
public void check(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        SnmpVarBind var = e.nextElement();
        SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
        req.registerCheckException(var, x);
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 17 with SnmpVarBind

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

the class SnmpMibAgent method concatVector.

private void concatVector(SnmpMibRequest req, Vector<SnmpVarBind> source) {
    for (Enumeration<SnmpVarBind> e = source.elements(); e.hasMoreElements(); ) {
        SnmpVarBind var = e.nextElement();
        // We need to duplicate the SnmpVarBind otherwise it is going
        // to be overloaded by the next get Next ...
        req.addVarBind(new SnmpVarBind(var.oid, var.value));
    }
}
Also used : SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 18 with SnmpVarBind

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

the class SnmpStandardObjectServer method check.

/**
     * Generic handling of the <CODE>check</CODE> operation.
     * <p> The default implementation of this method is to loop over the
     * varbind list associated with the sub-request and to call
     * <CODE>check(var.value, var.oid.getOidArc(depth), data);</CODE>
     * <pre>
     * public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
     *                   int depth)
     *    throws SnmpStatusException {
     *
     *    final Object data = req.getUserData();
     *
     *    for (Enumeration e= req.getElements(); e.hasMoreElements();) {
     *
     *        final SnmpVarBind var= (SnmpVarBind) e.nextElement();
     *
     *        try {
     *            // This method will generate a SnmpStatusException
     *            // if `depth' is out of bounds.
     *            //
     *            final long id = var.oid.getOidArc(depth);
     *            meta.check(var.value, id, data);
     *        } catch(SnmpStatusException x) {
     *            req.registerCheckException(var,x);
     *        }
     *    }
     * }
     * </pre>
     * <p> You can override this method if you need to implement some
     * specific policies for minimizing the accesses made to some remote
     * underlying resources, or if you need to implement some consistency
     * checks between the different values provided in the varbind list.
     * <p>
     *
     * @param meta  A pointer to the generated meta-data object which
     *              implements the <code>SnmpStandardMetaServer</code>
     *              interface.
     *
     * @param req   The sub-request that must be handled by this node.
     *
     * @param depth The depth reached in the OID tree.
     *
     * @exception SnmpStatusException An error occurred while accessing
     *  the MIB node.
     */
public void check(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final Object data = req.getUserData();
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            // This method will generate a SnmpStatusException
            // if `depth' is out of bounds.
            //
            final long id = var.oid.getOidArc(depth);
            meta.check(var.value, id, data);
        } catch (SnmpStatusException x) {
            req.registerCheckException(var, x);
        }
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 19 with SnmpVarBind

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

the class SnmpMib method getHandlers.

// --------------------------------------------------------------------
// PRIVATE METHODS
//---------------------------------------------------------------------
/**
     * This method builds the temporary request-tree that will be used to
     * perform the SNMP request associated with the given vector of varbinds
     * `list'.
     *
     * @param req The SnmpMibRequest object holding the varbind list
     *             concerning this MIB.
     * @param createflag Indicates whether the operation allow for creation
     *        of new instances (ie: it is a SET).
     * @param atomic Indicates whether the operation is atomic or not.
     * @param type Request type (from SnmpDefinitions).
     *
     * @return The request-tree where the original varbind list has been
     *         dispatched to the appropriate nodes.
     */
private SnmpRequestTree getHandlers(SnmpMibRequest req, boolean createflag, boolean atomic, int type) throws SnmpStatusException {
    // Build an empty request tree
    SnmpRequestTree handlers = new SnmpRequestTree(req, createflag, type);
    int index = 0;
    SnmpVarBind var;
    final int ver = req.getVersion();
    // For each varbind in the list finds its handling node.
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); index++) {
        var = e.nextElement();
        try {
            // Find the handling node for this varbind.
            root.findHandlingNode(var, var.oid.longValue(false), 0, handlers);
        } catch (SnmpStatusException x) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "Couldn't find a handling node for " + var.oid.toString());
            }
            //
            if (ver == SnmpDefinitions.snmpVersionOne) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tV1: Throwing exception");
                }
                // The index in the exception must correspond to the
                // SNMP index ...
                //
                final SnmpStatusException sse = new SnmpStatusException(x, index + 1);
                sse.initCause(x);
                throw sse;
            } else if ((type == SnmpDefinitions.pduWalkRequest) || (type == SnmpDefinitions.pduSetRequestPdu)) {
                final int status = SnmpRequestTree.mapSetException(x.getStatus(), ver);
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tSET: Throwing exception");
                }
                final SnmpStatusException sse = new SnmpStatusException(status, index + 1);
                sse.initCause(x);
                throw sse;
            } else if (atomic) {
                // Should never come here...
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tATOMIC: Throwing exception");
                }
                final SnmpStatusException sse = new SnmpStatusException(x, index + 1);
                sse.initCause(x);
                throw sse;
            }
            final int status = SnmpRequestTree.mapGetException(x.getStatus(), ver);
            if (status == SnmpStatusException.noSuchInstance) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering noSuchInstance");
                }
                var.value = SnmpVarBind.noSuchInstance;
            } else if (status == SnmpStatusException.noSuchObject) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering noSuchObject");
                }
                var.value = SnmpVarBind.noSuchObject;
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(), "getHandlers", "\tGET: Registering global error: " + status);
                }
                final SnmpStatusException sse = new SnmpStatusException(status, index + 1);
                sse.initCause(x);
                throw sse;
            }
        }
    }
    return handlers;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 20 with SnmpVarBind

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

the class SnmpGenericObjectServer method get.

/**
     * Execute an SNMP GET request.
     *
     * <p>
     * This method first builds the list of attributes that need to be
     * retrieved from the MBean and then calls getAttributes() on the
     * MBean server. Then it updates the SnmpMibSubRequest with the values
     * retrieved from the MBean.
     * </p>
     *
     * <p>
     * The SNMP metadata information is obtained through the given
     * <code>meta</code> object, which usually is an instance of a
     * <code>mibgen</code> generated class.
     * </p>
     *
     * <p><b><i>
     * This method is called internally by <code>mibgen</code> generated
     * objects and you should never need to call it directly.
     * </i></b></p>
     *
     * @param meta  The metadata object impacted by the subrequest
     * @param name  The ObjectName of the MBean impacted by this subrequest
     * @param req   The SNMP subrequest to execute on the MBean
     * @param depth The depth of the SNMP object in the OID tree.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request.<br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public void get(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    // java.lang.System.out.println(">>>>>>>>> GET " + name);
    final int size = req.getSize();
    final Object data = req.getUserData();
    final String[] nameList = new String[size];
    final SnmpVarBind[] varList = new SnmpVarBind[size];
    final long[] idList = new long[size];
    int i = 0;
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            nameList[i] = meta.getAttributeName(id);
            varList[i] = var;
            idList[i] = id;
            // Check the access rights according to the MIB.
            // The MBean might be less restrictive (have a getter
            // while the MIB defines the variable as AFN)
            //
            meta.checkGetAccess(id, data);
            //java.lang.System.out.println(nameList[i] + " added.");
            i++;
        } catch (SnmpStatusException x) {
            //java.lang.System.out.println("exception for " + nameList[i]);
            //x.printStackTrace();
            req.registerGetException(var, x);
        }
    }
    AttributeList result = null;
    int errorCode = SnmpStatusException.noSuchInstance;
    try {
        result = server.getAttributes(name, nameList);
    } catch (InstanceNotFoundException f) {
        //java.lang.System.out.println(name + ": instance not found.");
        //f.printStackTrace();
        result = new AttributeList();
    } catch (ReflectionException r) {
        //java.lang.System.out.println(name + ": reflexion error.");
        //r.printStackTrace();
        result = new AttributeList();
    } catch (Exception x) {
        result = new AttributeList();
    }
    final Iterator<?> it = result.iterator();
    for (int j = 0; j < i; j++) {
        if (!it.hasNext()) {
            //java.lang.System.out.println(name + "variable[" + j +
            //                           "] absent");
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerGetException(varList[j], x);
            continue;
        }
        final Attribute att = (Attribute) it.next();
        while ((j < i) && (!nameList[j].equals(att.getName()))) {
            //java.lang.System.out.println(name + "variable[" +j +
            //                           "] not found");
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerGetException(varList[j], x);
            j++;
        }
        if (j == i)
            break;
        try {
            varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
        } catch (SnmpStatusException x) {
            req.registerGetException(varList[j], x);
        }
    //java.lang.System.out.println(att.getName() + " retrieved.");
    }
//java.lang.System.out.println(">>>>>>>>> END GET");
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Aggregations

SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)35 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)18 SnmpTimeticks (com.sun.jmx.snmp.SnmpTimeticks)5 SnmpVarBindList (com.sun.jmx.snmp.SnmpVarBindList)5 SnmpOid (com.sun.jmx.snmp.SnmpOid)4 SnmpPduRequest (com.sun.jmx.snmp.SnmpPduRequest)3 SnmpValue (com.sun.jmx.snmp.SnmpValue)3 SnmpMibAgent (com.sun.jmx.snmp.agent.SnmpMibAgent)2 Vector (java.util.Vector)2 Attribute (javax.management.Attribute)2 AttributeList (javax.management.AttributeList)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)2 MBeanException (javax.management.MBeanException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)1