Net-SNMP snmptrapd Configuration


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 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/";
  3. the-who:/etc/snmp/ is the Perl script that snmptrapd calls to email trap messages to cse-staff.

FreeBSD snmptrapd Configuration

I couldn't make Net-SNMP 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 : : 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


  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
    % sudo snmptrapd -f -Le -d
    % sudo snmptrapd -f -Le -D ALL
    % net-snmp-config --configure-options

  1. To build a Linux, I had to build a net-snmp into /util. This procedure finally worked:
    % cd /tmp/net-snmp/net-snmp-
    % ./configure --prefix=/util/net-snmp- --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-
    % /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


  7. % man snmptrapd
  8. % man snmptrapd.conf
  9. % man snmpcmd
  10. % perldoc NetSNMP::TrapReceiver