HOWTO - Mailq monitor alerting

Questions and answers about how to do stuff
Post Reply
thewomble
Posts: 50
Joined: 17 Jan 2017 12:52

HOWTO - Mailq monitor alerting

Post by thewomble »

I have had an issue where the mail queue grew, which a reboot of EFA fixed, not sure why.

However I wanted to create a monitor when send an email alert once this got over a certain threshold, so I created a script as below and saved it to /usr/local/bin/mailqcheck.sh

Simply change alertemail variable to the email account you want send the email the alert to.
Change qmaxsize to a value you are happy with, in my case this was 1200 messages, I used 10 for testing.

I send the alert to our internal exchange server bypassing the EFA completely, so replace <internal mail server> to your FQDN. It must be resolvable by EFA, I had to get an entry in my local hostfile.

Code: Select all

#!/bin/bash
# Address to send email alerts to
alertemail=postmaster@<your local domain>

#Number of messages to queue to trigger an alert
qmaxsize=1200

queuecount=0
queuecount=`/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}'`

# uncomment below if you want see the queue size in realtime at console for checking.
# echo mailqueue is $queuecount;

if [ $queuecount -gt $qmaxsize ] ; then \n
echo 'Mail queue ' $(date) ' at EFA Mailgateway has ' $queuecount 'messages which is over the threshold limit of ' $qmaxsize | smtp="<internal mail server>:25" mail -s "Mailmx Queue Alert" -r "postmaster@<your local domain>" $alertemail
fi
Next I created a crond job to run every 5 minutes

Code: Select all

*/5 * * * * root /usr/local/bin/mailqcheck.sh
Not happend since, but at least I will know via email.
User avatar
pdwalker
Posts: 1553
Joined: 18 Mar 2015 09:16

Re: HOWTO - Mailq monitor alerting

Post by pdwalker »

Useful.

(I confess to being lazy in setting up the monitoring. My EFA has never had a problem I didn't create myself, so normally I'm watching when that happens.)
Post Reply