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
# (more implies a probable mail storm, so shut down the mail system)
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 perl_module.pl script found at
http://www.net-snmp.org/tutorial-5/toolkit/perl/index.html
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/perl_module.pl”;
then do:
/usr/local/bin/snmpwalk -v 2c -c whatever localhost .1.3.6.1.4.1.8072.999
It should return the following:
NET-SNMP-MIB::netSnmp.999.1.2.1 = STRING: “hello world”








cos on November 14th, 2009
If you use Net-SNMP’s “extend” feature you can run anything you like (as a separate process, at least) and provide output in a similar manner. As an added bonus, you don’t need to recompile Net-SNMP to add embedded perl support :)