check_mailq with SNMP or NRPE

Today I implemented a mailq check on our mail gateways. This isn´t a big deal, but I want to report from my experiences.

 

With SNMP

My first approach was to realize the check with help of SNMP. The website http://conshell.net/wiki/index.php/Using_Nagios_with_SNMP gives you a good idea on how to make that. Basically there are two ways to do this

–       use SNMP to execute a local nagios plugin (the nagios plugins package has to be installed for that)

–       use SNMP to execute a self-made script. (some like that: http://www.bary.at/mailq.htm)

After that you edit the snmpd.conf and restart the snmpd. This approach generally worked for me – only the performance data couldn´t be processed by rrd/pnp4nagios. Probably there is something wrong with the string (I’m strongly interested in a solution!). Since performance data is crucial to me, I decided to do the check with nrpe.

With NRPE

For this solution you need a working NRPE installation. Also you need the nagios-plugins to be installed. After that you just have to edit /etc/nagios/nrpe.cfg and add a custom check command by inserting the following line (edit to your needs):

command[check_mailq]=/usr/lib/nagios/plugins/check_mailq -w
<warnlevel> -c <critlevel> -M <postfix|sendmail|…>

No you only have to restart NRPE with rcnrpe restart. On the Nagios server you can fetch the information with ./check_nrpe –H <IP-Address> -c check_mailq.

To my surprise there was a minimal difference in the replied string, even though it was the same plug-in which generated it. The result is, that pnp4nagios was able to process the performance data. I would be really thankful if anyone has a good hint on how to get PerfData working with snmp.

PNP Template

Here is a very easy pnp4nagios template for the visualization of the PerfData:

<?php
$opt[1] = "--vertical-label \"Mail # \"  --title \"Unsent mails in 
Mailque for $hostname / $servicedesc\" ";
$def[1] = "DEF:var1=$rrdfile:$DS[1]:MAX " ;
$def[1] .= "AREA:var1#00FF00:\"unsent Messages \" " ;
$def[1] .= "LINE1:var1#000000:\"\" " ;

if ($WARN[1] != "") {
$def[1] .= "HRULE:$WARN[1]#FFFF00 ";
}
if ($CRIT[1] != "") {
$def[1] .= "HRULE:$CRIT[1]#FF0000 ";
}

$def[1] .= "GPRINT:var1:LAST:\"%6.0lg $UNIT[1] LAST \" ";
$def[1] .= "GPRINT:var1:MAX:\"%6.0lg $UNIT[1] MAX \" ";
$def[1] .= "GPRINT:var1:AVERAGE:\"%6.0lg $UNIT[1] AVERAGE \" ";
?>

Put this code into a file which matches the name of your checkcommandmailq pnp4nagios, for example: /omd/sites/SITENAME/etc/pnp4nagios/templates/check_mailq.php

Advertisements

About sitweak
Monitoring, Network, Firewall, Mobile Security. I´m totally into that stuff!

One Response to check_mailq with SNMP or NRPE

  1. tite says:

    Hey, thanks for the tips.
    I’ve coded custom bashs for transportation using snmp extensions and managed to get the performance data without issues by following the guidelines for plugin development of nagios. Basically what you need is output one line of text to stdout, and if there’s a pipeline in that line, whatever’s after the pipeline is considered to be perfdata. Best results are accomplished in the perfdata capture if you use the nagios output format “variable=value;w_threshold;c_threshold variable2=” … etc. though I’ve never appended thresholds to the output because I don’t like that.
    What I’ve had issues with is transporting the correct error codes back to nagios when using snmp extension. I lose the “Warning”, “Critical” and “Unknown” exit codes. I’ve worked around it by using check_snmp -r for checking for “OK” regexp on the output, which will alert with “Critical” state when not found.
    Gotta say though I’m not using PNP4Nagios, but nagiosgraph instead (recommended on the nagios site). Has worked like a charm.
    Well, there my 2 cents.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: