Using Net-SNMP to monitor processes and execute Perl scripts by hitting a MIB

One really cool feature about net-snmp is that it can monitor processes on a system. If snmpd notices that a process is no longer running, you can specify a script to be executed which can correct the problem. Lets take a look at some examples found here

At least one web server process must be running at all times:

proc httpd procfix httpd /etc/rc.d/init.d/httpd restart

There should never be more than 10 mail processes running:

proc sendmail 10 procfix sendmail /etc/rc.d/init.d/sendmail stop

There should be a single network management agent running (“There can be only one”):

proc snmpd 1 1

This can be an interesting use of Puppet, Chef, or CFengine, which are configuration management engines. Depending upon the type of host (webserver, mail server, etc.) you could set up and establish different types of snmpd.conf files for that environment. Granted, things like Solaris’ 10 SMF can automatically restart services, but this is a cool feature built into net-snmpd if you weren’t already aware that it was there! Secton 8 of the net-snmp README.Solaris file also has some other examples if you’re interested.

One other really cool feature about net-snmp is the ability to remotely execute Perl scripts by simply hitting a MIB. One example could be something like a “clean up disk space” script. Here’s an outtake from the README.Solaris file showing an example of the Perl script execution in action:

Net-SNMP may be compiled with Perl support by configuring like:

./configure -enable-embedded-perl …

Once you have compiled and installed net-snmp you can test the Perl capabilities of the final installation by doing the following:

Copy the script found at

to /usr/local/net-snmp and modify your /usr/local/share/snmp/snmpd.conf file to contain the entry:

perl do “/usr/local/net-snmp/”;

then do:

/usr/local/bin/snmpwalk -v 2c -c whatever localhost .

It should return the following:

NET-SNMP-MIB::netSnmp.999.1.2.1 = STRING: “hello world”

This article was posted by Matty on 2009-11-14 11:11:00 -0400 -0400