Dear Snmp Community, I have written a subagent (skeleton generated from subagent.m2c), where the while loop is as follows: /* you're main loop here... */ while(keep_running) { //check and send traps if (gTrapsAvailable) { gTrapsAvailable = false; //call traps for (const auto error : gErrors) { send_user_trap(error); //internally calls the send_v3trap() api } } /* if you use select(), see snmp_select_info() in snmp_api(3) */ /* --- OR --- */ agent_check_and_process(1); /* 0 == don't block */ //std::this_thread::sleep_for(std::chrono::milliseconds(100));
} My original problem was related to sending snmpv3 traps (send_v3trap() api) *when called from a different thread context*, then there were duplicate traps sent. /* excerpt from debug logs , total 4 times send_v3trap api called but 8 trap send) 2024-03-05 12:50:01 trap: send_trap -1 -1 iso.3.6.1.4.1.8072.3.2.10 2024-03-05 12:50:01 trap: sending trap type=12, version=193 to Local IPC: /var/agentx/master 2024-03-05 12:50:01 agentx_build: packet built okay test trap send_v3trap send 2024-03-05 12:50:01 trap: send_trap -1 -1 iso.3.6.1.4.1.8072.3.2.10 2024-03-05 12:50:01 trap: sending trap type=12, version=193 to Local IPC: /var/agentx/master 2024-03-05 12:50:01 agentx_build: packet built okay test trap send_v3trap send 2024-03-05 12:50:01 trap: send_trap -1 -1 iso.3.6.1.4.1.8072.3.2.10 2024-03-05 12:50:01 trap: sending trap type=12, version=193 to Local IPC: /var/agentx/master 2024-03-05 12:50:01 agentx_build: packet built okay test trap send_v3trap send 2024-03-05 12:50:01 trap: send_trap -1 -1 iso.3.6.1.4.1.8072.3.2.10 2024-03-05 12:50:01 trap: sending trap type=12, version=193 to Local IPC: /var/agentx/master 2024-03-05 12:50:01 agentx_build: packet built okay test trap send_v3trap send 2024-03-05 12:50:02 agentx_build: packet built okay 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: resending an inform for reqid=1933228917 2024-03-05 12:50:02 agentx_build: packet built okay 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: resending an inform for reqid=1933228919 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: received the inform response for reqid=1933228917 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: received the inform response for reqid=1933228919 2024-03-05 12:50:02 agentx_build: packet built okay 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: resending an inform for reqid=1933228921 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: received the inform response for reqid=1933228921 2024-03-05 12:50:02 agentx_build: packet built okay 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: resending an inform for reqid=1933228923 2024-03-05 12:50:02 trap: handle_inform_response for session UNKNOWN 2024-03-05 12:50:02 trap: received the inform response for reqid=1933228923 After reading some comments from the community my understanding is that since snmp is not thread safe so the trap api must be called from subagent thread context i.e. the while loop. It solves my duplicate trap issue, but the problem now is that main thread needs to wait for 15 seconds (ping timeout) when the agent_check_and_process(1) unblocks and then send the traps. I can run the agent_check_and_process(0) and make some sleep after, in worst case introducing a delay of some x milliseconds Therefore I want to ask 2 questions: 1. Is is possible to send the traps from different thread context (from subagent), if yes then how ? 2. If not, then somehow is it possible to set the timeout on the agent_check_and_process(int) api ? //I do not think decreasing the ping timeout is a good idea 3. If also not possible to set the timeout, then is there some other way / example like snmp_select_info ? Cheers Prankur -- Cheers Prankur
_______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders