Qmail queue check
author"Tomas Zeman <tzeman@volny.cz>"
Sat, 24 Jul 2010 16:03:30 +0200
changeset 6 283c9818387c
parent 5 572c5066aa57
child 7 0cd47f29bdfb
Qmail queue check
conf/daemontools.conf
scripts/qmail-qstat-check
--- a/conf/daemontools.conf	Wed Jul 21 12:03:07 2010 +0200
+++ b/conf/daemontools.conf	Sat Jul 24 16:03:30 2010 +0200
@@ -10,3 +10,5 @@
 UserParameter=sslserver.status[*],tail $1/current |grep 'status:'|tail -1|cut -d' ' -f 4|cut -d/ -f1
 UserParameter=qmail.status.local,tail /var/log/qmail/send/current |grep 'status:'|tail -1|cut -d' ' -f 4|cut -d/ -f1
 UserParameter=qmail.status.remote,tail /var/log/qmail/send/current |grep 'status:'|tail -1|cut -d' ' -f 6|cut -d/ -f1
+UserParameter=qmail.qstat.total,/opt/zabbix/scripts/qmail-qstat-check total
+UserParameter=qmail.qstat.unprocessed,/opt/zabbix/scripts/qmail-qstat-check unprocessed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/qmail-qstat-check	Sat Jul 24 16:03:30 2010 +0200
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+# Check of qmail queue.
+# Invocation:
+# qmail-qstat-check <stat>
+#	where stat is one of:
+#		total
+#		unprocessed
+#
+# Put following into /etc/sudoers:
+# zabbix  ALL=(ALL) NOPASSWD: /var/qmail/bin/qmail-qstat
+
+DIR="/tmp/zabbix"
+REPORT=qstat
+QSTAT="sudo /var/qmail/bin/qmail-qstat"
+
+[ -d $DIR ] || mkdir -p $DIR
+
+F=$DIR/$REPORT
+
+find $DIR -name $REPORT -mmin +10 -exec rm '{}' \;
+if [ ! -f $F ]; then
+	$QSTAT > $F.tmp || exit 1
+	mv $F.tmp $F
+fi
+
+if [ "x$1" = "xtotal" ]; then
+	head -1 $F | cut -d' ' -f4
+fi
+
+if [ "x$1" = "xunprocessed" ]; then
+	tail -1 $F | cut -d' ' -f8
+fi