Search in sources :

Example 1 with SnmpPduRequest

use of com.sun.jmx.snmp.SnmpPduRequest 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 the specified <CODE>InetAddress</CODE>
     * destination using the specified community string (and the ACL file
     * is not used).
     * <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 addr The <CODE>InetAddress</CODE> destination of the trap.
     * @param cs The community string to be used for the trap.
     * @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(InetAddress addr, String cs, 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;
    if (cs != null)
        pdu.community = cs.getBytes();
    else
        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);
    //
    if (addr != null)
        sendTrapPdu(addr, pdu);
    else
        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 2 with SnmpPduRequest

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

the class SnmpRequestHandler method makeResponsePdu.

/**
     * Here we make a response pdu from a request pdu.
     * We return null if there is no pdu to reply.
     */
private SnmpPduPacket makeResponsePdu(SnmpPduPacket reqPdu, Object userData) {
    SnmpAdaptorServer snmpServer = (SnmpAdaptorServer) adaptorServer;
    SnmpPduPacket respPdu = null;
    snmpServer.updateRequestCounters(reqPdu.type);
    if (reqPdu.varBindList != null)
        snmpServer.updateVarCounters(reqPdu.type, reqPdu.varBindList.length);
    if (checkPduType(reqPdu)) {
        respPdu = checkAcl(reqPdu);
        if (respPdu == null) {
            // reqPdu is accepted by ACLs
            if (mibs.size() < 1) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag, "makeResponsePdu", "Request " + reqPdu.requestId + " received but no MIB registered.");
                }
                return makeNoMibErrorPdu((SnmpPduRequest) reqPdu, userData);
            }
            switch(reqPdu.type) {
                case SnmpPduPacket.pduGetRequestPdu:
                case SnmpPduPacket.pduGetNextRequestPdu:
                case SnmpPduPacket.pduSetRequestPdu:
                    respPdu = makeGetSetResponsePdu((SnmpPduRequest) reqPdu, userData);
                    break;
                case SnmpPduPacket.pduGetBulkRequestPdu:
                    respPdu = makeGetBulkResponsePdu((SnmpPduBulk) reqPdu, userData);
                    break;
            }
        } else {
            // We send this response only if authResEnabled is true.
            if (!snmpServer.getAuthRespEnabled()) {
                // No response should be sent
                respPdu = null;
            }
            if (snmpServer.getAuthTrapEnabled()) {
                // A trap must be sent
                try {
                    snmpServer.snmpV1Trap(SnmpPduTrap.trapAuthenticationFailure, 0, new SnmpVarBindList());
                } catch (Exception x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "makeResponsePdu", "Failure when sending authentication trap", x);
                    }
                }
            }
        }
    }
    return respPdu;
}
Also used : SnmpPduBulk(com.sun.jmx.snmp.SnmpPduBulk) SnmpPduPacket(com.sun.jmx.snmp.SnmpPduPacket) SnmpPduRequest(com.sun.jmx.snmp.SnmpPduRequest) SnmpVarBindList(com.sun.jmx.snmp.SnmpVarBindList) SnmpTooBigException(com.sun.jmx.snmp.SnmpTooBigException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException)

Example 3 with SnmpPduRequest

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

the class SnmpRequestHandler method newErrorResponsePdu.

/**
     * Make a response pdu with the specified error status and index.
     * NOTE: the response pdu share its varBindList with the request pdu.
     */
private SnmpPduRequest newErrorResponsePdu(SnmpPduPacket req, int s, int i) {
    SnmpPduRequest result = newValidResponsePdu(req, null);
    result.errorStatus = s;
    result.errorIndex = i;
    result.varBindList = req.varBindList;
    ((SnmpAdaptorServer) adaptorServer).updateErrorCounters(result.errorStatus);
    return result;
}
Also used : SnmpPduRequest(com.sun.jmx.snmp.SnmpPduRequest)

Example 4 with SnmpPduRequest

use of com.sun.jmx.snmp.SnmpPduRequest 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 5 with SnmpPduRequest

use of com.sun.jmx.snmp.SnmpPduRequest 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)

Aggregations

SnmpPduRequest (com.sun.jmx.snmp.SnmpPduRequest)7 SnmpVarBindList (com.sun.jmx.snmp.SnmpVarBindList)4 SnmpTimeticks (com.sun.jmx.snmp.SnmpTimeticks)3 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)3 SnmpPduBulk (com.sun.jmx.snmp.SnmpPduBulk)1 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)1 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)1 SnmpTooBigException (com.sun.jmx.snmp.SnmpTooBigException)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketException (java.net.SocketException)1