1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/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
|