1

I have to send a SNMP trap towards my monitor with a script (perl for instance, or other) when some condition is met (e.g. when memory use or disk usage rise above 80%). I never write script so I have no idea how to do that.

This little script will allow me to test my java program which catch some traps on a given port.

Jolta
  • 2,620
  • 1
  • 29
  • 42
DouglasAdams
  • 490
  • 7
  • 19

1 Answers1

2

If all you want is to send a trap to test your trap receiver, you don't have to write a script! You can just download and install the net-snmp command line tools from http://net-snmp.sourceforge.net/download.html The command "snmptrap" is just what you're looking for.

If you want to do this from a shell script, of course you just ahve the script call the snmptrap binary.

If you are actually writing some monitoring script in perl, I still think the easiest way is to execute the snmptrap program from the perl script. You do also have the option of using some SNMP library. I've used Net::SNMP (unrelated to net-snmp) to good effect: https://metacpan.org/pod/Net::SNMP

szabgab
  • 6,202
  • 11
  • 50
  • 64
Jolta
  • 2,620
  • 1
  • 29
  • 42
  • I just made my shell script, so this part is OK. But I still don't know how to send a trap with net-snmp. If I try something like : snmptrap -v 1 -c public host '1.2.3.4.5.6' '192.193.194.195' 6 99 '55' 1.11.12.13.14.15 s "teststring" I get : getaddrinfo: host Name or service not known getaddrinfo("host", NULL, ...): Name or service not known snmptrap: zsh: exit 1 snmptrap -v 1 -c public host '1.2.3.4.5.6' '192.193.194.195' 6 99 '55' s – DouglasAdams Apr 02 '14 at 14:53
  • I think the host "host" does not exist on your network. Try putting in an IP address or existent host name instead. BTW, you don't need to put quotes around the OID strings. There is more info about the syntax of the command on the man page, "man snmptrap". – Jolta Apr 03 '14 at 06:20