Make sure the following packages are installed:
net-snmp-devel
net-snmp
net-snmp-libs
net-snmp-perl
net-snmp-utils
snmptt
nsca
Change the configuration of snmptrapd in “/etc/sysconfig/snmptrapd”:
OPTIONS="-On -Lsd -p /var/run/snmptrapd.pid"
These should all be available on the default repositiries and EPEL.
The file snmptrapd.conf should look like this:
# Example configuration file for snmptrapd # # No traps are handled by default, you must edit this file! # # authCommunity log,execute,net public # traphandle SNMPv2-MIB::coldStart /usr/bin/bin/my_great_script cold # authCommunity log,execute,net public traphandle default /usr/bin/snmptt
To send a snmptrap to Nagios, you need to make sure the configuration of snmptt submits the command to Nagios:
To convert mibs to snmptt.conf fiel we need to do a snmpttconvertmib:
snmpttconvertmib --in=FOUNDRY-SN-NOTIFICATION-MIB.mib --out=snmptt.conf.foundry --net_snmp_perl --exec="/etc/nagios/snmptrap/submit_check_result \$r snmptrap OK \"\$* \$x - \$X: \$D\""
The script that submits the info to Nagios using NSCA:
#!/bin/sh # Arguments: # $1 = host_name (Short name of host that the service is # associated with) # $2 = svc_description (Description of the service) # $3 = state_string (A string representing the status of # the given service - "OK", "WARNING", "CRITICAL" # or "UNKNOWN") # $4 = plugin_output (A text string that should be used # as the plugin output for the service checks) # # Convert the state string to the corresponding return code return_code=-1 case "$3" in OK) return_code=0 ;; WARNING) return_code=1 ;; CRITICAL) if [[ $4 =~ '.*up down.*UP_.*' ]] then echo "UPLINK!" return_code=2 elif [[ $4 =~ '.*up down.*MON_.*' ]] then echo "Monitored Klantpoort" return_code=2 elif [[ $4 =~ '.*up down.*' ]] then echo "Klantpoort" return_code=1 else echo "andere trap" return_code=2 fi ;; UNKNOWN) return_code=-1 ;; esac # pipe the service check info into the send_nsca program, which # in turn transmits the data to the nsca daemon on the central # monitoring server /usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/sbin/send_nsca 127.0.0.1 -c /etc/nagios/send_nsca.cfg
To have a check for this passive check, so people learn not to reschedule:
#! /usr/bin/perl -w use strict; use Getopt::Long; use vars qw($opt_V $opt_h $PROGNAME); use lib "/usr/lib/nagios/plugins/" ; use utils qw(%ERRORS &print_revision &support &usage); $PROGNAME = "check_snmptrap"; sub print_help (); sub print_usage (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; Getopt::Long::Configure('bundling'); GetOptions ("V" => \$opt_V, "version" => \$opt_V, "h" => \$opt_h, "help" => \$opt_h,); if ($opt_V) { print_revision($PROGNAME,': 0.1'); exit $ERRORS{'OK'}; } if ($opt_h) {print_help(); exit $ERRORS{'OK'};} print "CRITICAL - Je doet het fout (PEBKAC)\n"; exit $ERRORS{'CRITICAL'}; sub print_usage () { print "Usage: $PROGNAME \n"; } sub print_help () { print_revision($PROGNAME,': 0.1'); print "Copyright (c) 2010 Rob Hassing This plugin reports the usage of snmptraps "; print_usage(); print " -h, help "; }