com.sun.jmx.snmp.SnmpTimeticks Java Examples

The following examples show how to use com.sun.jmx.snmp.SnmpTimeticks. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnmpAdaptorServer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #2
Source File: SnmpAdaptorServer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #3
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #4
Source File: SnmpAdaptorServer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #5
Source File: SnmpAdaptorServer.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #6
Source File: SnmpAdaptorServer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #7
Source File: SnmpAdaptorServer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #8
Source File: SnmpAdaptorServer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #9
Source File: SnmpAdaptorServer.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #10
Source File: SnmpAdaptorServer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #11
Source File: SnmpAdaptorServer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private SnmpInformRequest snmpInformRequest(InetAddress addr,
                                            int port,
                                            String cs,
                                            SnmpInformHandler cb,
                                            SnmpOid trapOid,
                                            SnmpVarBindList varBindList)
    throws IllegalStateException, IOException, SnmpStatusException {

    if (!isActive()) {
        throw new IllegalStateException(
          "Start SNMP adaptor server before carrying out this operation");
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpInformRequest", "trapOid=" + trapOid);
    }

    // First, make an SNMP inform pdu:
    // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
    //
    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);

    // Next, send the pdu to the specified destination
    //
    openInformSocketIfNeeded() ;
    return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
}
 
Example #12
Source File: SnmpAdaptorServer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private SnmpInformRequest snmpInformRequest(InetAddress addr,
                                            int port,
                                            String cs,
                                            SnmpInformHandler cb,
                                            SnmpOid trapOid,
                                            SnmpVarBindList varBindList)
    throws IllegalStateException, IOException, SnmpStatusException {

    if (!isActive()) {
        throw new IllegalStateException(
          "Start SNMP adaptor server before carrying out this operation");
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpInformRequest", "trapOid=" + trapOid);
    }

    // First, make an SNMP inform pdu:
    // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
    //
    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);

    // Next, send the pdu to the specified destination
    //
    openInformSocketIfNeeded() ;
    return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
}
 
Example #13
Source File: SnmpAdaptorServer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private SnmpInformRequest snmpInformRequest(InetAddress addr,
                                            int port,
                                            String cs,
                                            SnmpInformHandler cb,
                                            SnmpOid trapOid,
                                            SnmpVarBindList varBindList)
    throws IllegalStateException, IOException, SnmpStatusException {

    if (!isActive()) {
        throw new IllegalStateException(
          "Start SNMP adaptor server before carrying out this operation");
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpInformRequest", "trapOid=" + trapOid);
    }

    // First, make an SNMP inform pdu:
    // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
    //
    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);

    // Next, send the pdu to the specified destination
    //
    openInformSocketIfNeeded() ;
    return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
}
 
Example #14
Source File: SnmpAdaptorServer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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) ;
}
 
Example #15
Source File: SnmpAdaptorServer.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private SnmpInformRequest snmpInformRequest(InetAddress addr,
                                            int port,
                                            String cs,
                                            SnmpInformHandler cb,
                                            SnmpOid trapOid,
                                            SnmpVarBindList varBindList)
    throws IllegalStateException, IOException, SnmpStatusException {

    if (!isActive()) {
        throw new IllegalStateException(
          "Start SNMP adaptor server before carrying out this operation");
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpInformRequest", "trapOid=" + trapOid);
    }

    // First, make an SNMP inform pdu:
    // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
    //
    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);

    // Next, send the pdu to the specified destination
    //
    openInformSocketIfNeeded() ;
    return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
}
 
Example #16
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private SnmpInformRequest snmpInformRequest(InetAddress addr,
                                            int port,
                                            String cs,
                                            SnmpInformHandler cb,
                                            SnmpOid trapOid,
                                            SnmpVarBindList varBindList)
    throws IllegalStateException, IOException, SnmpStatusException {

    if (!isActive()) {
        throw new IllegalStateException(
          "Start SNMP adaptor server before carrying out this operation");
    }
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpInformRequest", "trapOid=" + trapOid);
    }

    // First, make an SNMP inform pdu:
    // We clone varBindList and insert sysUpTime and snmpTrapOid variables.
    //
    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);

    // Next, send the pdu to the specified destination
    //
    openInformSocketIfNeeded() ;
    return informSession.makeAsyncRequest(addr, cs, cb, fullVbl, port) ;
}
 
Example #17
Source File: SnmpAdaptorServer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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) ;
}
 
Example #18
Source File: SnmpAdaptorServer.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
 
Example #19
Source File: SnmpAdaptorServer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V2 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * <BR>The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 * <BR>The variable list included in the outgoing trap is composed of
 * the following items:
 * <UL>
 * <LI><CODE>sysUpTime.0</CODE> with the value specified by
 *     <CODE>time</CODE></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 peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param trapOid The OID identifying the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV2Trap(SnmpPeer peer,
                       SnmpOid trapOid,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV2Trap(peer.getDestAddr(),
               peer.getDestPort(),
               p.getRdCommunity(),
               trapOid,
               varBindList,
               time);
}
 
Example #20
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified parameters (and the ACL file is not
 * used).
 * Note that if the specified <CODE>InetAddress</CODE> destination is null,
 * then the ACL file mechanism is used.
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param cs The community string to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
public void snmpV1Trap(InetAddress addr,
                       SnmpIpAddress agentAddr,
                       String cs,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {
    snmpV1Trap(addr,
               trapPort,
               agentAddr,
               cs,
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #21
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) ;

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu);
    else
        sendTrapPdu(pdu);
}
 
Example #22
Source File: SnmpAdaptorServer.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V2 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * <BR>The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 * <BR>The variable list included in the outgoing trap is composed of
 * the following items:
 * <UL>
 * <LI><CODE>sysUpTime.0</CODE> with the value specified by
 *     <CODE>time</CODE></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 peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param trapOid The OID identifying the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV2Trap(SnmpPeer peer,
                       SnmpOid trapOid,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV2Trap(peer.getDestAddr(),
               peer.getDestPort(),
               p.getRdCommunity(),
               trapOid,
               varBindList,
               time);
}
 
Example #23
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
 
Example #24
Source File: SnmpAdaptorServer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V2 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * <BR>The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 * <BR>The variable list included in the outgoing trap is composed of
 * the following items:
 * <UL>
 * <LI><CODE>sysUpTime.0</CODE> with the value specified by
 *     <CODE>time</CODE></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 peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param trapOid The OID identifying the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV2Trap(SnmpPeer peer,
                       SnmpOid trapOid,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV2Trap(peer.getDestAddr(),
               peer.getDestPort(),
               p.getRdCommunity(),
               trapOid,
               varBindList,
               time);
}
 
Example #25
Source File: SnmpAdaptorServer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) ;

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu);
    else
        sendTrapPdu(pdu);
}
 
Example #26
Source File: SnmpAdaptorServer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>InetAddress</CODE>
 * destination using the specified parameters (and the ACL file is not
 * used).
 * Note that if the specified <CODE>InetAddress</CODE> destination is null,
 * then the ACL file mechanism is used.
 *
 * @param addr The <CODE>InetAddress</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param cs The community string to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit defined
 *            by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
public void snmpV1Trap(InetAddress addr,
                       SnmpIpAddress agentAddr,
                       String cs,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {
    snmpV1Trap(addr,
               trapPort,
               agentAddr,
               cs,
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #27
Source File: SnmpAdaptorServer.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
 
Example #28
Source File: SnmpAdaptorServer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) ;

    // Next, send the pdu to the specified destination
    //
    if(addr != null)
        sendTrapPdu(addr, pdu);
    else
        sendTrapPdu(pdu);
}
 
Example #29
Source File: SnmpAdaptorServer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void snmpV1Trap(InetAddress addr,
                        int port,
                        SnmpIpAddress agentAddr,
                        String cs,
                        SnmpOid enterpOid,
                        int generic,
                        int specific,
                        SnmpVarBindList varBindList,
                        SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "snmpV1Trap", "generic=" + generic + ", specific=" +
              specific);
    }

    // First, make an SNMP V1 trap pdu
    //
    SnmpPduTrap pdu = new SnmpPduTrap() ;
    pdu.address = null ;
    pdu.port = port ;
    pdu.type = pduV1TrapPdu ;
    pdu.version = snmpVersionOne ;

    //Diff start
    if(cs != null)
        pdu.community = cs.getBytes();
    else
        pdu.community = null ;
    //Diff end

    // Diff start
    if(enterpOid != null)
        pdu.enterprise = enterpOid;
    else
        pdu.enterprise = enterpriseOid ;
    //Diff end
    pdu.genericTrap = generic ;
    pdu.specificTrap = specific ;
    //Diff start
    if(time != null)
        pdu.timeStamp = time.longValue();
    else
        pdu.timeStamp = getSysUpTime();
    //Diff end

    if (varBindList != null) {
        pdu.varBindList = new SnmpVarBind[varBindList.size()] ;
        varBindList.copyInto(pdu.varBindList);
    }
    else
        pdu.varBindList = null ;

    if (agentAddr == null) {
        // If the local host cannot be determined,
        // we put 0.0.0.0 in agentAddr
        try {
            final InetAddress inetAddr =
                (address!=null)?address:InetAddress.getLocalHost();
            agentAddr = handleMultipleIpVersion(inetAddr.getAddress());
        }  catch (UnknownHostException e) {
            byte[] zeroedAddr = new byte[4];
            agentAddr = handleMultipleIpVersion(zeroedAddr);
        }
    }

    pdu.agentAddr = agentAddr;

    // Next, send the pdu to the specified destination
    //
    // Diff start
    if(addr != null)
        sendTrapPdu(addr, pdu) ;
    else
        sendTrapPdu(pdu);

    //End diff
}
 
Example #30
Source File: SnmpAdaptorServer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sends a trap using SNMP V2 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * <BR>The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 * <BR>The variable list included in the outgoing trap is composed of
 * the following items:
 * <UL>
 * <LI><CODE>sysUpTime.0</CODE> with the value specified by
 *     <CODE>time</CODE></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 peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param trapOid The OID identifying the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV2Trap(SnmpPeer peer,
                       SnmpOid trapOid,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV2Trap(peer.getDestAddr(),
               peer.getDestPort(),
               p.getRdCommunity(),
               trapOid,
               varBindList,
               time);
}