How to remotely read mailq using Nagios and NRPE

How to get the data on the size of mailq on Sendmail server, using Nagios and NRPE.

1. Installing NRPE agent on mail server (host whose mailq we want to know the size of)
So NRPE agent may be installed using yum (not sure abot this) or untar the tarred file (I used this), but not both!!! :
# wget (CentOS 5-6)
# tar xzf linux-nrpe-agent.tar.gz
# cd linux-nrpe-agent
# ./fullinstall
Here you will be asked the IP of Nagios server.

2. Check if check_mailq plugin works on mail server :
It will be installed in /local/nagios/libexec because of the NRPE agent.
# /usr/local/nagios/libexec
# ./check_mailq -w2 -c5 -Msendmail -v
If you get such a error :
Can’t locate in @INC (@INC contains: nagios/plugins /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./check_mailq line 36.
BEGIN failed–compilation aborted at ./check_mailq line 36.
In script check_mailq change this line :
use lib “nagios/plugins”;
into this :
use lib “/usr/local/nagios/libexec” ; where this is the location of nrpe agent
Afrter this plugin will work OK on local (mail) server :
# ./check_mailq -w2 -c5 -Msendmail -v
/usr/bin/mailq = /var/spool/mqueue is empty
/usr/bin/mailq = Total requests: 0
OK: mailq is empty|unsent=0;2;5;0
In configuration file /usr/local/nagios/etc/nrpe.cfg you need to add the line which describes the commans which we want to execute remotely :
command[check_mailq]=/usr/local/nagios/libexec/check_mailq -M sendmail -w 3 -c 2
Also in u /etc/sudoers file you need to add that account nagios on mail host can, witount password, execute mailq command :
nagios ALL = (root) NOPASSWD: /usr/bin/mailq
In file /usr/local/nagios/libexec/check_mailq, exchange line :
if (! open (MAILQ, “$utils::PATH_TO_MAILQ | ” ) ) {
with line :
if (! open (MAILQ, “/usr/bin/sudo $utils::PATH_TO_MAILQ | ” ) ) {

3. Tie up mail host and Nagios server using NRPE
What is NRPE?
Here is a short explanation : NRPE – Nagios Remote Plugin Executor, NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. Good link on how to do it.

Since we already have NRPE installed on mail host, following files need to be checked : /etc/xinetd.d/nrpe and /usr/local/nagios/etc/nrpe.cfg, is our Nagios server the only IP that can do nrpe querries (and of course MUST be here also, and between it and Nagios server IP is only blank space). If this is not so, change accordingly, and restart xinetrd service.
# chkconfig nrpe on so that service goes up after server restart

If you get such error while starting nrpe service on mail host :
nrpe[5105]: Network server bind failure (98: Address already in use)
That means that you have installed nrpe twice. Uninstall one.

Test if nrpe is up :
# netstat -an|grep 5666
tcp 0 0* LISTEN

4. Nagios server and what is to be done here
You should have check_nrpe plugin in folder /usr/lib/nagios/plugins.
Test if it can “talk” with remote mail host :
# ./check_nrpe -H
NRPE v2.14
Also the following should be defined on Nagios server : host that you intend to check upon, command that you will use for testing, and service which will use this command on defined mail host.
Host definition : file /etc/nagios/hosts.cfg
define host{
host_name mail.liste-
alias mail.liste-
parents gw- this is for graph
hostgroups mail_grupa host group name in which mail host will be, you have to add it there also
normal_check_interval 5 this is in minutes, if you do not set it, default is 60min
retry_check_interval 3
max_check_attempts 5
active_checks_enabled 0
passive_checks_enabled 0
check_period 24×7
contact_groups IT-racunari
notification_interval 60
notification_period 24×7
notification_options d,u,r
notifications_enabled 1

define hostgroup{
hostgroup_name mail_grupa
alias Grupa sa mail serverima
members mail.izvodi-,mail.liste-
Definition of command : in file /etc/Nagios/commands.cfg
#NRPE checkup for mailq on Linux
define command{
command_name check_mailq_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c check_mailq
Definition of service : file /etc/Nagios/services.cfg
define service {
host_name liste.mail-
service_description NRPE mailq provera
check_command check_mailq_nrpe!/
check_period 24×7
max_check_attempts 5
normal_check_interval 20
retry_check_interval 3
contact_groups IT-racunari
notification_interval 60
notification_period 24×7
notification_options w,u,c,r

And in the end test from Nagios server :
# ./check_nrpe -H -c check_mailq
OK: mailq is empty|unsent=0;2;3;0

Note : where are files on our mail host, which have to do with NRPE
Configuration files : /usr/local/nagios/etc/nrpe.cfg and /usr/local/nagios/etc/nrpe.cfg
In both files should be the same.
Executable file : /etc/xinetd.d/nrpe

Good links : link1, link2, link3

This entry was posted in Linux and tagged , , . Bookmark the permalink.

Comments are closed.