A nagios snmp plugin that obeys snmp.conf

So there is a currently unresolved issue with the check_snmp nagios plugin where it doesn’t use the snmp.conf file. I use v3 of the protocol, and don’t want to have to put the big long string everywhere in the nagios configuration file:

define command{
  command_name check_snmp_cpu
  command_line $USER1$/check_snmp -H $HOSTADDRESS$ -w 2 -c 4 -u "cpu" -P 3 -L authPriv -a MD5 -U snmpmonitor -A "have a look at what I have to offer" -x des -X "have a look at what I have to offer" -o .1.3.6.1.4.1.2021.11.10.0
}

With this in my /etc/snmp/snmp.conf file:

defVersion 3
defSecurityName snmpmonitor
defSecurityLevel authPriv
defPassphrase "have a look at what I have to offer"

I don’t have to give any arguments to the snmp commands on the command line. The check_snmp plugin forks out to the snmpget command, but does so in such a way that the snmp.conf file isn’t used. So I thought to myself, why not write a simple script that forks out to snmpget?

Here is my check_snmp.pl script, and my nagios command is now simply:

define command{
  command_name check_snmp_cpu
  command_line /usr/bin/perl $USER1$/check_snmp.pl -w 2 -c 4 -m " cpu" -- $HOSTADDRESS$ .1.3.6.1.4.1.2021.11.10.0
}

Much, much shorter. And if I ever change the passphrase, I don’t have to do it in 20 places.

Be warned, it took me all of 45 minutes on it and it “works for me”. Your results may vary. I release is to you all under the public domain. Have fun.

2 thoughts on “A nagios snmp plugin that obeys snmp.conf”

  1. Nice solution!

    However, the same can be achieved by using macros (nagios-lingo for “variables”) in /etc/nagios3/resources.cfg


    # Sets $USER1$ to be the path to the plugins
    $USER1$=/usr/lib/nagios/plugins

    # Sets $USER2$ to be the path to event handlers
    $USER2$=monkey
    $USER3$="all your base"
    $USER4$="do you want to be a pepper too?"

    And then calling that in the command definitions, like so:


    define command{
    command_name snmp_cpustats
    command_line /usr/lib/nagios/plugins/check_snmp -P 3 -L authPriv -A '$USER3' -X '$USER4' -U '$USER2$' -H '$HOSTADDRESS$' -o .1.3.6.1.4.1.2021.11.9.0,.1.3.6.1.4.1.2021.11.10.0,.1.3.6.1.4.1.2021.11.11.0 -l 'CPU usage (user system idle)' -u '%'
    }

Leave a Reply to mverwijs Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>