Browse Source

Add posfix plugin

Emmanuel Bouthenot 7 years ago
parent
commit
4638e14f7f

+ 4 - 0
plugins/client/postfix/conf/postfix.conf

@@ -0,0 +1,4 @@
+UserParameter=postfix.deferred[*],sudo /etc/zabbix/scripts/postfix -s deferred
+UserParameter=postfix.active[*],sudo /etc/zabbix/scripts/postfix -s active
+UserParameter=postfix.sent[*],sudo /etc/zabbix/scripts/postfix -s sent
+UserParameter=postfix.bounced[*],sudo /etc/zabbix/scripts/postfix -s bounced

+ 62 - 0
plugins/client/postfix/scripts/postfix

@@ -0,0 +1,62 @@
+#!/bin/sh
+
+# {{{ Variables
+SPOOLS="deferred active sent bounced"
+SPOOL=""
+# }}}
+
+# {{{ usage()
+usage() {
+cat <<EOH
+USAGE: $(basename "$0") [OPTIONS]
+
+Count emails handled by postfix (using logtail)
+
+Options:
+    -h  Shows this help
+    -s  Spool ($(echo "${SPOOLS}" | sed 's/ / or /g'))
+EOH
+}
+# }}}
+
+# {{{ main()
+while getopts "hs:" OPT ; do
+    case "$OPT" in 
+        h)
+            usage
+            exit 0
+            ;;
+        s)
+            SPOOL="$OPTARG"
+            ;;
+    esac
+done
+
+if [ -z "${SPOOL}" ]; then
+    printf "[ERR] Spool is missing\n"
+    usage
+    exit 1
+fi
+
+case "${SPOOL}" in
+    deferred)
+        /usr/sbin/postqueue -p | egrep -c "^[0-9A-F]{10}[^*]"
+        ;;
+    active)
+        /usr/sbin/postqueue -p | egrep -c "^[0-9A-F]{10}[*]"
+        ;;
+    sent)
+        /usr/sbin/logtail -f /var/log/mail.log -o /var/tmp/zabbix_sent.log | grep -c "postfix/smtp.*status=sent"
+        ;;
+    bounced)
+        /usr/sbin/logtail -f /var/log/mail.log -o /var/tmp/zabbix_bounces.log | grep -c "postfix/smtp.*status=bounced"
+        ;;
+    *)
+        printf "[ERR] info '${SPOOL}' not available in [$(echo "${SPOOLS}" | sed 's/ /, /g')]\n"
+        ;;
+esac
+
+exit 0
+# }}}
+
+# vim: foldmethod=marker foldlevel=0 foldenable

+ 4 - 0
plugins/client/postfix/sudo/postfix

@@ -0,0 +1,4 @@
+#
+# Permit to zabbix user to execute 'postfix' plugin
+#
+zabbix ALL=NOPASSWD: /etc/zabbix/scripts/postfix