Is it possible to monitor Postfix e-mail queue on an e-mail server running Ubuntu 8.04 LTS? I would like notification when the queue is 250 e-mails
Monitoring e-mail queue on postfix
Votes:
0
Best Answer
Votes:
0
You can monitor the queues with a simple bashscript:
#!/bin/bash # 20.06.2011 - JJaritsch @ ANEXIA Internetdienstleistungs GmbH # [email protected] 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
Save this script and make it executable (0755 is enough) for the snmpd user. The next step is to add the following line to your snmpd.conf:
exec postqueue /path/to/your/snmp_monitor_postqueue.sh
If you want to use sudo, you can add this line:
exec postqueue /usr/bin/sudo /path/to/your/snmp_monitor_postqueue.sh
In case of sudo you also have to add the following to your sudoers file (so there is no auth required to execute this script):
snmp ALL=(ALL) NOPASSWD: /path/to/your/snmp_monitor_postqueue.sh
Reload your snmpd - you will find the count-result in .1.3.6.1.4.1.2021.8.1.101.* (for example in .1.3.6.1.4.1.2021.8.1.101.1 if you have no other additional lines in the snmpd.conf).
7 Replies
Votes:
0
There is not built-in function of PRTG to do this. It may be possible to create a custom sensor using some programming language and this information, but this will not come too soon from Paessler: http://stackoverflow.com/questions/226699/how-to-monitor-postfix-mta-status
Votes:
0
You can monitor the queues with a simple bashscript:
#!/bin/bash # 20.06.2011 - JJaritsch @ ANEXIA Internetdienstleistungs GmbH # [email protected] 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
Save this script and make it executable (0755 is enough) for the snmpd user. The next step is to add the following line to your snmpd.conf:
exec postqueue /path/to/your/snmp_monitor_postqueue.sh
If you want to use sudo, you can add this line:
exec postqueue /usr/bin/sudo /path/to/your/snmp_monitor_postqueue.sh
In case of sudo you also have to add the following to your sudoers file (so there is no auth required to execute this script):
snmp ALL=(ALL) NOPASSWD: /path/to/your/snmp_monitor_postqueue.sh
Reload your snmpd - you will find the count-result in .1.3.6.1.4.1.2021.8.1.101.* (for example in .1.3.6.1.4.1.2021.8.1.101.1 if you have no other additional lines in the snmpd.conf).
Votes:
0
Juergen - your solution works perfectly! Thanks so much for the writeup.
Votes:
0
Juergen, Thank you for your script! But after adding the sensor "SNMP Custom" I have error "No such instance (SNMP error # 223)".
But when tested in the SNMP Tester are no problems!!! The number of messages in the queue is displayed correctly. How to be in this case? Thank U.
Votes:
0
Thanks for the script. It works fine.
After update to Ubuntu version 18.04 sudo did not work to start the script. exec postqueue /usr/bin/sudo /path/to/your/snmp_monitor_postqueue.sh Error: no tty present and no askpass program specified
My solution: exec postqueue /path/to/your/snmp_monitor_postqueue.sh
Votes:
0
This appears to require SELinux to be disabled/permissive to work.
Without sudo you get postqueue: fatal: open /etc/postfix/main.cf: Permission denied
With sudo you get sudo: PAM account management error: System error
Using sudo and with SELinux disabled/permissive gets around the issue but does anyone have a solution that keeps SELinux in play?
Add comment