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
Code: Select all
*/5 * * * * root /usr/local/bin/mailqcheck.sh