Search in sources :

Example 6 with SnmpVarBind

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

the class SnmpAdaptorServer method snmpV2Trap.

private void snmpV2Trap(InetAddress addr, int port, String cs, SnmpOid trapOid, SnmpVarBindList varBindList, SnmpTimeticks time) throws IOException, SnmpStatusException {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        final StringBuilder strb = new StringBuilder().append("trapOid=").append(trapOid).append("\ncommunity=").append(cs).append("\naddr=").append(addr).append("\nvarBindList=").append(varBindList).append("\ntime=").append(time).append("\ntrapPort=").append(port);
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "snmpV2Trap", strb.toString());
    }
    // First, make an SNMP V2 trap pdu
    // We clone varBindList and insert sysUpTime and snmpTrapOid
    //
    SnmpPduRequest pdu = new SnmpPduRequest();
    pdu.address = null;
    pdu.port = port;
    pdu.type = pduV2TrapPdu;
    pdu.version = snmpVersionTwo;
    if (cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null;
    SnmpVarBindList fullVbl;
    if (varBindList != null)
        fullVbl = varBindList.clone();
    else
        fullVbl = new SnmpVarBindList(2);
    // Only difference with other
    SnmpTimeticks sysUpTimeValue;
    if (time != null)
        sysUpTimeValue = time;
    else
        sysUpTimeValue = new SnmpTimeticks(getSysUpTime());
    //End of diff
    fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0);
    fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue), 0);
    pdu.varBindList = new SnmpVarBind[fullVbl.size()];
    fullVbl.copyInto(pdu.varBindList);
    // Diff start
    if (addr != null)
        sendTrapPdu(addr, pdu);
    else
        sendTrapPdu(pdu);
//End diff
}
Also used : SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind) SnmpPduRequest(com.sun.jmx.snmp.SnmpPduRequest) SnmpVarBindList(com.sun.jmx.snmp.SnmpVarBindList) SnmpTimeticks(com.sun.jmx.snmp.SnmpTimeticks)

Example 7 with SnmpVarBind

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

the class SnmpAdaptorServer method snmpV2Trap.

/**
     * Sends a trap using SNMP V2 trap format.
     * <BR>The trap is sent to each destination defined in the ACL file
     * (if available). If no ACL file or no destinations are available,
     * the trap is sent to the local host.
     * <BR>The variable list included in the outgoing trap is composed of
     * the following items:
     * <UL>
     * <LI><CODE>sysUpTime.0</CODE> with its current value</LI>
     * <LI><CODE>snmpTrapOid.0</CODE> with the value specified by
     *     <CODE>trapOid</CODE></LI>
     * <LI><CODE>all the (oid,values)</CODE> from the specified
     *     <CODE>varBindList</CODE></LI>
     * </UL>
     *
     * @param trapOid The OID identifying the trap.
     * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
     *
     * @exception IOException An I/O error occurred while sending the trap.
     * @exception SnmpStatusException If the trap exceeds the limit defined
     *            by <CODE>bufferSize</CODE>.
     */
@Override
public void snmpV2Trap(SnmpOid trapOid, SnmpVarBindList varBindList) throws IOException, SnmpStatusException {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "snmpV2Trap", "trapOid=" + trapOid);
    }
    // First, make an SNMP V2 trap pdu
    // We clone varBindList and insert sysUpTime and snmpTrapOid
    //
    SnmpPduRequest pdu = new SnmpPduRequest();
    pdu.address = null;
    pdu.port = trapPort;
    pdu.type = pduV2TrapPdu;
    pdu.version = snmpVersionTwo;
    pdu.community = null;
    SnmpVarBindList fullVbl;
    if (varBindList != null)
        fullVbl = varBindList.clone();
    else
        fullVbl = new SnmpVarBindList(2);
    SnmpTimeticks sysUpTimeValue = new SnmpTimeticks(getSysUpTime());
    fullVbl.insertElementAt(new SnmpVarBind(snmpTrapOidOid, trapOid), 0);
    fullVbl.insertElementAt(new SnmpVarBind(sysUpTimeOid, sysUpTimeValue), 0);
    pdu.varBindList = new SnmpVarBind[fullVbl.size()];
    fullVbl.copyInto(pdu.varBindList);
    // Next, send the pdu to all destinations defined in ACL
    //
    sendTrapPdu(pdu);
}
Also used : SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind) SnmpPduRequest(com.sun.jmx.snmp.SnmpPduRequest) SnmpVarBindList(com.sun.jmx.snmp.SnmpVarBindList) SnmpTimeticks(com.sun.jmx.snmp.SnmpTimeticks)

Example 8 with SnmpVarBind

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

the class SnmpRequestHandler method makeGetBulkResponsePdu.

/**
     * Here we make the response pdu for a bulk request.
     * At this level, the result is never null.
     */
private SnmpPduPacket makeGetBulkResponsePdu(SnmpPduBulk req, Object userData) {
    SnmpVarBind[] respVarBindList;
    // RFC 1905, Section 4.2.3, p14
    int L = req.varBindList.length;
    int N = Math.max(Math.min(req.nonRepeaters, L), 0);
    int M = Math.max(req.maxRepetitions, 0);
    int R = L - N;
    if (req.varBindList == null) {
        //
        return newValidResponsePdu(req, null);
    }
    // Split the request into subrequests.
    //
    splitBulkRequest(req, N, M, R);
    SnmpPduPacket result = executeSubRequest(req, userData);
    if (result != null)
        return result;
    respVarBindList = mergeBulkResponses(N + (M * R));
    // Now we remove useless trailing endOfMibView.
    //
    // respVarBindList[m2] item and next are going to be removed
    int m2;
    int t = respVarBindList.length;
    while ((t > N) && (respVarBindList[t - 1].value.equals(SnmpVarBind.endOfMibView))) {
        t--;
    }
    if (t == N)
        m2 = N + R;
    else
        // Trivial, of course...
        m2 = N + ((t - 1 - N) / R + 2) * R;
    if (m2 < respVarBindList.length) {
        SnmpVarBind[] truncatedList = new SnmpVarBind[m2];
        for (int i = 0; i < m2; i++) {
            truncatedList[i] = respVarBindList[i];
        }
        respVarBindList = truncatedList;
    }
    //
    return newValidResponsePdu(req, respVarBindList);
}
Also used : SnmpPduPacket(com.sun.jmx.snmp.SnmpPduPacket) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 9 with SnmpVarBind

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

the class SnmpSubNextRequestHandler method updateResult.

/**
     * The method updates a given var bind list with the result of a
     * previsouly invoked operation.
     * Prior to calling the method, one must make sure that the operation was
     * successful. As such the method getErrorIndex or getErrorStatus should be
     * called.
     */
protected void updateResult(SnmpVarBind[] result) {
    final int max = varBind.size();
    for (int i = 0; i < max; i++) {
        // May be we should control the position ...
        //
        final int index = translation[i];
        final SnmpVarBind elmt = (SnmpVarBind) ((NonSyncVector) varBind).elementAtNonSync(i);
        final SnmpVarBind vb = result[index];
        if (vb == null) {
            result[index] = elmt;
            /* end of NPCTE fix for bugid 4381195 */
            continue;
        }
        final SnmpValue val = vb.value;
        if ((val == null) || (val == SnmpVarBind.endOfMibView)) {
            /* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
            if ((elmt != null) && (elmt.value != SnmpVarBind.endOfMibView))
                result[index] = elmt;
            //    vb.value = SnmpVarBind.endOfMibView;
            continue;
        /* end of NPCTE fix for bugid 4381195 */
        }
        /* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
        if (elmt == null)
            continue;
        if (elmt.value == SnmpVarBind.endOfMibView)
            continue;
        // Now we need to take the smallest oid ...
        //
        int comp = elmt.oid.compareTo(vb.oid);
        if (comp < 0) {
            // Take the smallest (lexicographically)
            //
            result[index] = elmt;
        } else {
            if (comp == 0) {
                // Take the deeper within the reply
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", " oid overlapping. Oid : " + elmt.oid + "value :" + elmt.value);
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Already present varBind : " + vb);
                }
                SnmpOid oid = vb.oid;
                SnmpMibAgent deeperAgent = server.getAgentMib(oid);
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Deeper agent : " + deeperAgent);
                }
                if (deeperAgent == agent) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "The current agent is the deeper one. Update the value with the current one");
                    }
                    result[index].value = elmt.value;
                }
            /*
                      Vector v = new Vector();
                      SnmpMibRequest getReq = createMibRequest(v,
                      version,
                      null);
                      SnmpVarBind realValue = new SnmpVarBind(oid);
                      getReq.addVarBind(realValue);
                      try {
                      deeperAgent.get(getReq);
                      } catch(SnmpStatusException e) {
                      e.printStackTrace();
                      }

                      if(isDebugOn())
                      trace("updateResult", "Biggest priority value is : " +
                      realValue.value);

                      result[index].value = realValue.value;
                    */
            }
        }
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpMibAgent(com.sun.jmx.snmp.agent.SnmpMibAgent) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 10 with SnmpVarBind

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

the class SnmpSubNextRequestHandler method updateRequest.

/**
     * The method updates the varbind list of the subrequest.
     */
protected void updateRequest(SnmpVarBind var, int pos) {
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(), "updateRequest", "Copy :" + var);
    }
    int size = varBind.size();
    translation[size] = pos;
    final SnmpVarBind newVarBind = new SnmpVarBind(var.oid, var.value);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpSubRequestHandler.class.getName(), "updateRequest", "Copied :" + newVarBind);
    }
    varBind.addElement(newVarBind);
}
Also used : 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