How to monitor qmail mail queue (check_mailq alternative)

Written by - 2 comments

Published on - Listed in Nagios Linux Shell Mail Monitoring


Although the official Nagios plugin check_mailq has a special -M (for MTA) switch where qmail can be used as option, it still cannot really handle the qmail mail queue. I even added the correct location of qmail-qstat into utils.pm, but I still wasn't able to monitor the mail queue on a specific qmail mail server.

To be able to monitor the qmail mail queue, I made the following steps:

1. Backed up the original check_mailq plugin and created a new check_mailq:

#!/bin/bash
#########################################
# special check_mailq for qmail by claudio kuenzler
# 2013-04-18 Created script
# 2014-05-07 Bugfix in getopt
#########################################

# Check for people who need help - aren't we all nice ;-)
#########################################################################
if [ "${1}" = "--help" -o "${#}" = "0" ];
       then
       echo -e "Wrong option given. Use -w and -c";
       exit 1;
fi

# Get user-given variables
#########################################################################
while getopts "w:c:" Input;
do
       case ${Input} in
       w)      warning=${OPTARG};;
       c)      critical=${OPTARG};;
       *)      echo "Wrong option given. Use -w and -c"
               exit 1
               ;;
       esac
done

mailq=$(/var/qmail/bin/qmail-qstat | sed -n '1p' | awk -F': ' '{print $2}')

if [[ $mailq -gt $warning ]]
then echo "MAILQ CRITICAL - $mailq mails in queue|qmailq=$mailq;$warning;$critical"; exit 2
elif [[ $mailq -gt $critical ]]
then echo "MAILQ WARNING - $mailq mails in queue|qmailq=$mailq;$warning;$critical"; exit 1
elif [[ $mailq -le 0 ]]
then echo "MAILQ UNKNOWN - $mailq mails in queue cant really be..."; exit 3
else echo "MAILQ OK - $mailq mails in queue|qmailq=$mailq;$warning;$critical"; exit 0
fi

echo "MAILQ UNKNOWN - Should never come here"
exit 3


2. Add nrpe user to the group qmail.

In my case this was the user "daemon", which can be verified like this:

ps aux | grep nrpe
daemon   12042  0.0  0.0  39980  1080 ?        Ss   Apr03   0:19 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d

usermod -a -G qmail daemon



Add a comment

Show form to leave a comment

Comments (newest first)

ck from Switzerland wrote on May 7th, 2014:

Thanks, BlackJack. I have added the second colon after c (to expect a value).


BlackJack from wrote on May 7th, 2014:

There is a colon missing in the first getopt argument. It should read … getopts "w:c:" ….


RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder