Fast nagios exim mail queue plugin replacement

We had a problem with the nagios check_mailq plugin at work, it kept timing out. So I wrote a simple bash script (instead of 610 lines of perl) which is “compatible” with check_mailq (supports the same arguments) which uses “exim4″ and is very quick. Just drop it in /usr/local/bin/check_mailq_simple.sh and adjust your nagios conf to use that instead of check_mailq

#!/bin/bash
 
WARNING=""
CRITICAL=""
MAILER=""
TIMER=""
 
while getopts "w:c:M:t" optionName; do
  case "${optionName}" in
    w) WARNING="${OPTARG}";;
    c) CRITICAL="${OPTARG}";;
    M) MAILER="${OPTARG}";;
    t) TIMER="${OPTARG}";;
  esac
done
 
MAILS_IN_QUEUE=`sudo /usr/sbin/exim4 -bpc`
 
if [[ ${MAILS_IN_QUEUE} -gt ${CRITICAL} ]]; then
  echo "CRITICAL: mailq is ${MAILS_IN_QUEUE} (threshold w = ${CRITICAL})|unsent=${MAILS_IN_QUEUE};${WARNING};${CRITICAL};0"
  exit 2
elif [[ ${MAILS_IN_QUEUE} -gt ${WARNING} ]]; then
  echo "WARNING: mailq is ${MAILS_IN_QUEUE} (threshold w = ${WARNING})|unsent=${MAILS_IN_QUEUE};${WARNING};${CRITICAL};0"
  exit 1
elif [[ ${MAILS_IN_QUEUE} -lt ${WARNING} ]]; then
  echo "OK: mailq is ${MAILS_IN_QUEUE} (threshold w = ${WARNING})|unsent=${MAILS_IN_QUEUE};${WARNING};${CRITICAL};0"
  exit 0
else
  echo "ERROR: something did not go right"
  exit 2
fi

This has been tested on Debian sarge.

2 Responses to “Fast nagios exim mail queue plugin replacement”

  1. Arvy Says:

    Very cool. Helped a lot. Thanks!

  2. its@4commerce Says:

    Hi!

    Great script (with a little bug)! When the value of WARNING is equal to the number of mails in mailq it produces a notification with “ERROR: something did not go right”.
    If you insert

    elif [[ ${MAILS_IN_QUEUE} -eq ${WARNING} ]]; then
    echo “WARNING: mailq is ${MAILS_IN_QUEUE} (threshold w = ${WARNING})|unsent=${MAILS_IN_QUEUE};${WARNING};${CRITICAL};0″
    exit 1

    everything is okay.

Leave a comment

(required)
(required) (will not be published)

(Comment moderation is in use. Please do not submit your comment twice)