fbpx

How to monitor Postfix queue length using an SNMP monitor

Background

It’s essential to monitor email queues if you’re an Internet service provider or email service provider. Any of your 1000s of email users might have chosen an insecure password meaning that a script kiddy might come and hack their email box, and in the process unleash 1000s of messages of even 100 000s of messages meaning your email server will be blacklisted. Although it’s recoverable, the quicker you find the problem, the easier it will be to solve. If you leave the problem for more than a few days, you might end up spending days, weeks, and sometimes even months fixing the problem. The fact of the matter is once you have been banned by a couple of high profile spam detection services, delisting is not a joke.

Queue monitoring using Postfix and PRTG

Postfix is a really popular MTA and often used to send emails. This article covers a method for monitoring the Postfix queue. There are other methods as well, but this method is really straightforward and works if you have also have PRTG installed. The article is the work of a forum contributor at PRTG with small modifications.

The Script

cat /etc/postfix/snmp_monitor_postqueue.sh

#!/bin/bash
# 20.06.2011 - JJaritsch @ ANEXIA Internetdienstleistungs GmbH
# jj @ anexia.at

queuelength=`/usr/sbin/postqueue -p | tail -n1 | awk '{print $5}'`
queuecount=`echo $queuelength | grep "[0-9]"`

if [ "$queuecount" == "" ]; then
        echo 0;
else
        echo ${queuelength};
fi
exit 35

Change owner, assign correct permissions, and make executable:

chown postfix:postfix snmp_monitor_postqueue.sh
chmod 755 snmp_monitor_postqueue.sh
chmod +x snmp_monitor_postqueue.sh

Add to /etc/snmp/snmpd.conf

snmpd.conf:

exec postqueue /usr/bin/sudo /etc/postfix/snmp_monitor_postqueue.sh

Add to /etc/sudoers

snmp ALL=(ALL) NOPASSWD: /path/to/your/snmp_monitor_postqueue.sh

Restart service

service snmpd restart

In PRTG / Add Sensor / SNMP Custom

.1.3.6.1.4.1.2021.8.1.101.1

To test from the command line:

snmpwalk -c your_community -v 2c localhost 1.3.6.1.4.1.2021.8.1.101.1

References

  • https://kb.paessler.com/en/topic/21223-monitoring-e-mail-queue-on-postfix

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top