1

我正在尝试添加获取 TRAP V3 的选项(我可以获得 TRAP V1 和 V2)。

这是会话初始化

public void CreateSession()
{
    logger.debug(".in");        
    System.out.println("Waiting to receive traps .......");

    api = new SnmpAPI();
    api.setDebug( true );
    session = new SnmpSession(api);
    session.addSnmpClient(this);
    udpOpt = new UDPProtocolOptions();
    udpOpt.setLocalPort(TRAP_PORT);
    session.setProtocolOptions(udpOpt);
    try
    {
        session.open();
        String message="Succes to bind port: "+session.getLocalPort();
        logger.info(message);
        System.out.println(message);
    }
    catch (Exception ex)
    {
        String message = "Failed to open session - Port in use or permission denied. \n Message-  "+ ex.getMessage() + "\n Will exit from Trap process. ";
        logger.error(message, ex);
        System.err.println(message);
        throw new RuntimeException(message);
    }   
}

每次我在 V3 中设置设备时,我都会使用 USMUtils 方法执行发现并将其注册到表中。init_v3_parameters

 private void initV3Parameters(NEData neData) throws InterruptedException
{
    logger.debug("in.");
    try
    {
        UDPProtocolOptions udpOptions = new UDPProtocolOptions();
        udpOptions.setLocalPort(TRAP_PORT);
        udpOptions.setRemoteHost(neData.m_szIpAddress);
         USMUtils.init_v3_parameters(
                neData.usmUser,
                null,
                Integer.valueOf(neData.authProtocol),
                neData.authPassword,
                neData.privPassword,
                udpOptions,
                session,
                false,
                Integer.valueOf(neData.privProtocol));
        printToLog("success",neData);
    }
    catch (SnmpException exp) {
        logger.error(exp.getMessage()+" for ip = "+neData.m_szIpAddress,exp);
        discoveredDeque.put(neData);
        printToLog("failed",neData);
    }


}

当 TRAP V1 或 V2 到货时,它就具有此功能,并且可以完美运行。但我也想添加 V3

/**
 * Receives incoming PDUs and adds them to the traps queue. Notifies the
 * internal thread on the arrival of each PDU.
 */
public boolean callback (SnmpSession session, SnmpPDU pdu, int requestID)
{
    logger.info("in session= "+session+" ,pdu= "+pdu+" ,requestID = "+requestID);
    if (pdu == null)
    {
        logger.info("Received null PDU");
    }
    else
    {
        // Add the PDU to the end of the traps queue.
        // Notify the internal thread.
        try
        {
            synchronized (this)
            {
                Object t = m_Traps.addElement(pdu);
                if (t != null)
                {
                    // The new trap replaced an old one.
                    logger.info("Queue full: replaced old PDU");
                }
                notify();
            }
        }
        catch (Exception ex)
        {
           logger.error(ex.getMessage(),ex);
        }
    }
    // All PDUs are handled, so true should always be returned.
    return true;
}

我已经debugPrint实现了SnmpClient,似乎 AdventNet 得到了 TRAP 但没有做任何事情......

SNMP 代理使用 NetSNMP 实现。

让 AdventNet 处理 V3 TRAP 缺少什么?

这是正确的回调函数吗?

public boolean callback (SnmpSession session, SnmpPDU pdu, int requestID)

4

0 回答 0