As i am having quite some problems configuring nagios to work with traps i'll try to post a few steps to start with...
I'm runnning nagios (compiled from source) on Debian.
You'll need snmptrapd (it's part of snmpd), snmptt and obviously nagios.
configure /etc/default/snmpd to run snmptrapd with the -On option and restrat snmpd
these are the two lines i needed to change:
TRAPDOPTS='-On -Lsd -p /var/run/snmptrapd.pid'
for testing i created two MIB definition files as shown here:
net-snmp.org/wiki/index.php/ ... MIv1_Traps
if you installed snmptt you should also have snmpttmibtranslate, run it against all mib files you have:
for i in *; do snmpttconvertmib --in=$i --out=/etc/snmp/snmpttconf/all.conf; done
this translates the mib file sand puts them in the out file.
modify /etc/snmp/snmptt.ini to use that last file...
snmptt_conf_files = <<END
Now you can modify snmptt.ini to use DEBUG, set the debug file too...
remeber to restart snmptt
If you cretaed the two MIB files above you should now be able to send a trap with:
snmptrap -v 2c -c public 10.10.10.10 "" NET-SNMP-EXAMPLES-MIB::netSnmpExampleHeartbeatNotification netSnmpExampleHeartbeatRate i 123456
change community and receiving host IP address to meet your needs and you should see the trap managed by snmptt in the debug file.
If all worked up to here we now need to modify the all.conf file so that snmptt does something with the trap, we want it to be sent to nagios.
first we modify the trap we are intersted in (in this case the demo notification) so that it calls an eventhandler (which will write the info in the nagios.cmd file)
search the right trap in all.conf and add an EXEC line:
EVENT netSnmpExampleHeartbeatNotification .22.214.171.124.4.1.8072.2.3.0.1 "Status Events" Normal
FORMAT An example notification, used to illustrate the $*
EXEC /usr/local/nagios/libexec/eventhandlers/submit_check_result localhost testtrap 1 "test trap recevied"
don't touch the SDESC part...
we are telling snmptt to run the submit_check_result script with some parameters. theorically we should use $r as hostname, but that gives us the FQDN on localhost and that's not what we wnat right now.
now we need the script itself:
create the eventhandlers directory if you don't already have it and then
echo ""$data"] PROCESS_SERVICE_CHECK_RESULT;$1;$2;$3;$4" >> /usr/local/nagios/var/rw/nagios.cmd
now create a passive check named traptest for the localhost in nagios, restart nagios and snmptt and you should get the trap in nagios (it will be a warning having an exit code of 1.
Add the user snmptt to the nagcmd group
usermod -a -G nagcmd snmptt
or the submit_check-result script run by user snmptt won't be able to write in the nagios command file
In the EXEC command od all.cpnf we used localhost, to use the correct hostname you need to associate the IP address of the trap generator to the hostname you use in nagios in the /etc/hosts file and change the EXEC lines:
To receive Link Down and up traps i used the following:
EXEC /usr/local/nagios/libexec/eventhandlers/submit_check_result $r "IF-MIB Trap
s" 1 "Link Change: $* state changed to Down"
on the host i defined a service called "IF-MIB Traps" and this is what i get:
hostname IF-MIB Traps OK 05-04-2011 12:11:15 0d 0h 5m 57s 1/1 Link Change: 16 state changed to Up
I hope i didn't miss any important passages in writing this down... let me know if you have problems