Net-SNMP snmptrapd Configuration

Introduction

In CSE, we use Net-SNMP snmptrapd to receive notifications about renewable resource capacities on our monitored servers. Our monitored resources include:

  • Disk Usage. We typically receive an alert when a disk is less than 20% free.
  • Load Average. We receive alerts if 1-, 5-, and 15-minute average loads exceed a preconfigured threshold.
  • Memory Usage.
  • Processes. We receive alerts if the numbers of monitored processes vary from preconfigured minimum and maximum thresholds.

How it Works

  1. Each CSE SNMP-monitored host must run Net-SNMP snmpd with a customized snmpd.conf. Look for snmpd.conf in /etc/snmp/ on Linux systems and in /usr/local/etc/snmp/ on FreeBSD systems. In snmpd.conf, the informsink and/or trap2sink tokens must be assigned the value of our trap receiver, the-who.cse.buffalo.edu. The snmpd process must be running.
  2. the-who:/etc/snmp/snmptrapd.conf must be properly configured and snmptrapd must be running. snmptrapd.conf contains a reference to the NetSNMP embedded Perl features:
    
    perl NetSNMP::TrapReceiver::register("all", \&my_receiver);
    perl do "/etc/snmp/mytrapdmail.pl";
    
    
  3. the-who:/etc/snmp/mytrapmail.pl is the Perl script that snmptrapd calls to email trap messages to cse-staff.

FreeBSD snmptrapd Configuration

I couldn't make Net-SNMP 5.4.2.1 snmptrapd work properly on a FreeBSD system, so this section does not describe our current setup.

  1. In /etc/rc.conf, snmptrapd_enable="YES".
  2. Enable this host to receive traps. In /etc/hosts.allow, add:
    
    #
    # Permit SNMP-monitored machines to snmptrap to us
    #
    snmptrapd : 128.205.0.0/255.255.0.0 : allow
    
    
  3. Make sure configuration directives land in /usr/local/etc/snmp/snmptrapd.conf.
  4. Add an entry to /etc/newsyslog.conf to rotate the logfiles:
    
    /var/log/snmptrapd.log                  644  7     100  *     JC
    
    

Notes

  1. % sudo snmpconf -i
  2. % sudo snmpconf -g basic_setup
  3. Verify that a SNMP trap receiver is receiving traps on interface xl0, port 162:
    % sudo tcpdump -i xl0 port 162
    
  4. 
    % sudo snmptrapd -f -Le -d
    
    
  5. 
    % sudo snmptrapd -f -Le -D ALL
    
    
  6. 
    % net-snmp-config --configure-options
    
    

NetSNMP::TrapReceiver.pm

  1. To build a Linux NetSNMP::TrapReceiver.pm, I had to build a net-snmp into /util. This procedure finally worked:
    
    % cd /tmp/net-snmp/net-snmp-5.4.2.1
    % ./configure --prefix=/util/net-snmp-5.4.2.1 --with-default-snmp-version="2"
    % make
    % sudo make install
    
    
    ... then go back into the net-snmp source and install the Perl stuff:
    
    % cd /tmp/net-snmp/net-snmp-5.4.2.1/perl
    % /util/perl/bin/perl Makefile.PL -NET-SNMP-CONFIG="sh /util/net-snmp/bin/net-snmp-config" -NET-SNMP-IN-SOURCE=true
    % make
    % make test
    % sudo make install
    
    

References

  1. http://en.wikipedia.org/wiki/Net-SNMP
  2. http://www.net-snmp.org/docs/man/snmptrapd.html
  3. http://www.net-snmp.org/docs/man/snmptrapd.conf.html
  4. http://www.net-snmp.org/wiki/index.php/Main_Page
  5. http://net-snmp.sourceforge.net/docs/FAQ.html#How_do_I_send_traps_and_no...
  6. http://fixunix.com/snmp/175135-trap-handling.html
  7. % man snmptrapd
  8. % man snmptrapd.conf
  9. % man snmpcmd
  10. % perldoc NetSNMP::TrapReceiver