postfix 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. # {{{ Variables
  3. SPOOLS="deferred active sent bounced"
  4. SPOOL=""
  5. # }}}
  6. # {{{ usage()
  7. usage() {
  8. cat <<EOH
  9. USAGE: $(basename "$0") [OPTIONS]
  10. Count emails handled by postfix (using logtail)
  11. Options:
  12. -h Shows this help
  13. -s Spool ($(echo "${SPOOLS}" | sed 's/ / or /g'))
  14. EOH
  15. }
  16. # }}}
  17. # {{{ main()
  18. while getopts "hs:" OPT ; do
  19. case "$OPT" in
  20. h)
  21. usage
  22. exit 0
  23. ;;
  24. s)
  25. SPOOL="$OPTARG"
  26. ;;
  27. esac
  28. done
  29. if [ -z "${SPOOL}" ]; then
  30. printf "[ERR] Spool is missing\n"
  31. usage
  32. exit 1
  33. fi
  34. case "${SPOOL}" in
  35. deferred)
  36. /usr/sbin/postqueue -p | egrep -c "^[0-9A-F]{10}[^*]"
  37. ;;
  38. active)
  39. /usr/sbin/postqueue -p | egrep -c "^[0-9A-F]{10}[*]"
  40. ;;
  41. sent)
  42. /usr/sbin/logtail -f /var/log/mail.log -o /var/tmp/zabbix_sent.log | grep -c "postfix/smtp.*status=sent"
  43. ;;
  44. bounced)
  45. /usr/sbin/logtail -f /var/log/mail.log -o /var/tmp/zabbix_bounces.log | grep -c "postfix/smtp.*status=bounced"
  46. ;;
  47. *)
  48. printf "[ERR] info '${SPOOL}' not available in [$(echo "${SPOOLS}" | sed 's/ /, /g')]\n"
  49. ;;
  50. esac
  51. exit 0
  52. # }}}
  53. # vim: foldmethod=marker foldlevel=0 foldenable