1

Can we write the code for sending user defined traps rather than those mentioned in snmpd using Net-SNMP API like below to send traps netsnmp_send_traps(), send_v2trap(), send_v3trap()?

I am not planning to write any MIB module. So I don't expect that my trap should be going through snmpd (Agent Daemon).

The idea I want to implement is that sending trap from external code to snmptrapd which will receive traps and forward it to configured trap receiver to get more familiar with Net-SNMP library.

  • 1
    You should be able to read the source code of snmptrap, http://www.net-snmp.org/wiki/index.php/TUT:snmptrap – Lex Li Dec 05 '13 at 02:57
  • I dont want to use snmptrap as it is a command. If I use snmptrapd command in my code, it gets unnecessarily forked to execute by syscall(). I want to overcome this. Any method to overcome this? – Chaitanya Gulhane Dec 11 '13 at 18:17
  • But it is fully open sourced, so you can see what API it makes use of to send the traps. I am not asking you to call the command. – Lex Li Dec 12 '13 at 02:56
  • ok. Thanks for the comment. Can you please tell me what is the difference between traps sent by agent and traps sent by snmptrap command? – Chaitanya Gulhane Dec 13 '13 at 11:02
  • The bytes in the packet are all the same, but you should pay attention to the port used to send out the packet. – Lex Li Dec 13 '13 at 13:59
  • ok. But why two different methods are provided to send traps? Any significant reason? Or any particular use? – Chaitanya Gulhane Dec 15 '13 at 16:23
  • SNMP has multiple versions, which requires different methods to construct packets. You might refer to the RFC documents for more info. – Lex Li Dec 15 '13 at 23:38
  • Can you please let me know the exact RFC number for this? – Chaitanya Gulhane Dec 17 '13 at 06:48
  • http://stackoverflow.com/questions/8679137/snmp-v1-v2c-and-v3-trap-differece – Lex Li Dec 17 '13 at 07:54
  • Also is that the thing that we can send traps for the things we are monitoring through snmpd and if it is not monitoring it cannot send traps from snmpd? I think we can send user defined traps by snmptrap and traps for the system status like CPU usage, Disk Usage are sent through snmpd if they are being monitored by snmpd. – Chaitanya Gulhane Dec 17 '13 at 10:31
  • If you extend snmpd with your objects, you should try to send TRAPs in your extensions. If you don't, of course you can try to use `snmptrap` or your own app to send TRAPs. Technically, the receiver won't tell any differences. If you do have any other questions, try to post them as new questions. – Lex Li Dec 18 '13 at 04:39

1 Answers1

0

There is no Net-SNMP API provided. We can just fork-exec Net-SNMP command to send trap.