Search in sources :

Example 6 with SnmpVarBindList

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

SnmpVarBindList (com.sun.jmx.snmp.SnmpVarBindList)6 SnmpTimeticks (com.sun.jmx.snmp.SnmpTimeticks)5 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)5 SnmpPduRequest (com.sun.jmx.snmp.SnmpPduRequest)4 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 InetAddress (java.net.InetAddress)1 SocketException (java.net.SocketException)1 Vector (java.util.Vector)1