root / plugins / postfix / postfix_stats @ 17f78427
Historique | Voir | Annoter | Télécharger (3,56 ko)
| 1 | fe764769 | Kenyon Ralph | #!/bin/sh |
|---|---|---|---|
| 2 | d1d668f6 | Cristian Deluxe | # -*- sh -*- |
| 3 | |||
| 4 | : <<=cut |
||
| 5 | |||
| 6 | =head1 NAME |
||
| 7 | |||
| 8 | postfix_stats - Munin plugin to monitor postfix statistics. |
||
| 9 | |||
| 10 | =head1 APPLICABLE SYSTEMS |
||
| 11 | |||
| 12 | Any system where pflogsumm script can be executed. |
||
| 13 | |||
| 14 | =head1 CONFIGURATION |
||
| 15 | |||
| 16 | 156f0d84 | Cristian Deluxe | There is no default configuration. This is an example config for Ubuntu: |
| 17 | d1d668f6 | Cristian Deluxe | |
| 18 | 335d856d | Ander Punnar | [postfix_stats*] |
| 19 | group adm |
||
| 20 | b13a180e | Ander Punnar | env.logfiles /var/log/mail.log /var/log/mail.log.1 |
| 21 | d1d668f6 | Cristian Deluxe | env.pflogsumm pflogsumm |
| 22 | |||
| 23 | env.logfiles contains space separated syslog logfiles, usually current log |
||
| 24 | 17f78427 | Lars Kruse | and previous log. You can add more log files if you want, but this may |
| 25 | 156f0d84 | Cristian Deluxe | increase the time required for analysis. |
| 26 | d1d668f6 | Cristian Deluxe | |
| 27 | 156f0d84 | Cristian Deluxe | env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually |
| 28 | 17f78427 | Lars Kruse | downloaded and installed, or "pflogsumm" if it was installed by a package |
| 29 | 156f0d84 | Cristian Deluxe | manager (like apt-get). |
| 30 | d1d668f6 | Cristian Deluxe | |
| 31 | ba37da55 | Ander Punnar | Use the last part of the symlink name for filtering by hostname from logfile, |
| 32 | which contains logs from multiple hosts (e.g. received via rsyslog from remote |
||
| 33 | hosts). |
||
| 34 | 1fe97cbf | Ander Punnar | |
| 35 | 56a367da | Ander Punnar | For example: |
| 36 | |||
| 37 | cd /etc/munin/plugins |
||
| 38 | ln -s /path/to/postfix_stats postfix_stats_HOSTNAME |
||
| 39 | |||
| 40 | d1d668f6 | Cristian Deluxe | =head1 INTERPRETATION |
| 41 | |||
| 42 | 156f0d84 | Cristian Deluxe | This plugin displays the messages: received, delivered, rejected... |
| 43 | Average per minute is made and it shows the total message count. |
||
| 44 | It is useful to know the load and messages being processed. |
||
| 45 | d1d668f6 | Cristian Deluxe | |
| 46 | =head1 MAGIC MARKERS |
||
| 47 | |||
| 48 | #%# family=auto |
||
| 49 | #%# capabilities=autoconf |
||
| 50 | |||
| 51 | =head1 VERSION |
||
| 52 | 1fe97cbf | Ander Punnar | 0.3 support for hostname grep (useful when multiple hosts in one log) |
| 53 | d1d668f6 | Cristian Deluxe | 0.2 plugin completely rewritten |
| 54 | 0.1 first release. |
||
| 55 | |||
| 56 | =head1 BUGS |
||
| 57 | |||
| 58 | None known |
||
| 59 | |||
| 60 | =head1 AUTHOR |
||
| 61 | |||
| 62 | Originally: David Obando (david@cryptix.de) |
||
| 63 | Modified by: github.com/cristiandeluxe |
||
| 64 | 1fe97cbf | Ander Punnar | Modified by: github.com/4nd3r |
| 65 | d1d668f6 | Cristian Deluxe | Thanks to: sumpfralle |
| 66 | |||
| 67 | =head1 LICENSE |
||
| 68 | |||
| 69 | GPLv2 |
||
| 70 | |||
| 71 | =cut |
||
| 72 | fe764769 | Kenyon Ralph | |
| 73 | #set -xv |
||
| 74 | bd0ff094 | Ander Punnar | MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}"
|
| 75 | daf5b94a | Cristian Deluxe | |
| 76 | 390c8050 | Ander Punnar | FILTER_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//') |
| 77 | 8e5775ce | Ander Punnar | |
| 78 | daf5b94a | Cristian Deluxe | # shellcheck disable=SC2154 |
| 79 | d1d668f6 | Cristian Deluxe | PFLOGSUMM="${pflogsum}"
|
| 80 | [ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" |
||
| 81 | 17fcfc37 | Cristian Deluxe | |
| 82 | d1d668f6 | Cristian Deluxe | # Fields (Array to avoid code duplication) must be space separated |
| 83 | FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded" |
||
| 84 | 48ab3322 | Cristian Deluxe | |
| 85 | 17fcfc37 | Cristian Deluxe | # |
| 86 | # Autoconf Section |
||
| 87 | # |
||
| 88 | 918602cd | Cristian Deluxe | if [ "$1" = 'autoconf' ]; then |
| 89 | d1d668f6 | Cristian Deluxe | # Check if pflogsumm exist |
| 90 | if [ -z "${PFLOGSUMM}" ]
|
||
| 91 | 17fcfc37 | Cristian Deluxe | then |
| 92 | d1d668f6 | Cristian Deluxe | echo 'no (pflogsum not found in your system)' |
| 93 | 17fcfc37 | Cristian Deluxe | else |
| 94 | 918602cd | Cristian Deluxe | echo 'yes' |
| 95 | 17fcfc37 | Cristian Deluxe | fi |
| 96 | d1d668f6 | Cristian Deluxe | exit 0 |
| 97 | 17fcfc37 | Cristian Deluxe | fi |
| 98 | |||
| 99 | # |
||
| 100 | # Config Section |
||
| 101 | # |
||
| 102 | 918602cd | Cristian Deluxe | if [ "$1" = 'config' ]; then |
| 103 | 390c8050 | Ander Punnar | if [ -n "${FILTER_HOSTNAME}" ]; then
|
| 104 | echo "graph_title Postfix statistics for ${FILTER_HOSTNAME}"
|
||
| 105 | 8e5775ce | Ander Punnar | else |
| 106 | echo 'graph_title Postfix statistics' |
||
| 107 | fi |
||
| 108 | 918602cd | Cristian Deluxe | echo 'graph_vlabel Postfix statistics' |
| 109 | echo 'graph_category mail' |
||
| 110 | echo 'graph_scale no' |
||
| 111 | 8e2025a9 | Cristian Deluxe | echo 'graph_period minute' |
| 112 | 918602cd | Cristian Deluxe | echo 'graph_total Total' |
| 113 | 48ab3322 | Cristian Deluxe | |
| 114 | # Generate config for each field |
||
| 115 | d1d668f6 | Cristian Deluxe | for i in $FIELDS_ARR; do |
| 116 | 48ab3322 | Cristian Deluxe | echo "${i}.label ${i}"
|
| 117 | echo "${i}.type DERIVE"
|
||
| 118 | echo "${i}.min 0"
|
||
| 119 | 87a6a775 | Cristian Deluxe | echo "${i}.draw AREASTACK"
|
| 120 | 48ab3322 | Cristian Deluxe | done |
| 121 | |||
| 122 | exit 0 |
||
| 123 | 17fcfc37 | Cristian Deluxe | fi |
| 124 | |||
| 125 | # |
||
| 126 | # Plugin Script |
||
| 127 | # |
||
| 128 | |||
| 129 | # Variable to store the pflogsumm result. |
||
| 130 | 390c8050 | Ander Punnar | if [ -n "${FILTER_HOSTNAME}" ]; then
|
| 131 | b43f35f1 | Ander Punnar | # shellcheck disable=SC2086 |
| 132 | 16fcdeca | Ander Punnar | TMP_RAW=$(grep -Fh " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill)
|
| 133 | 8e5775ce | Ander Punnar | else |
| 134 | b43f35f1 | Ander Punnar | # shellcheck disable=SC2086 |
| 135 | b3590739 | Ander Punnar | TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG})
|
| 136 | 8e5775ce | Ander Punnar | fi |
| 137 | 17fcfc37 | Cristian Deluxe | |
| 138 | # Parse value from Raw result |
||
| 139 | 17f78427 | Lars Kruse | # |
| 140 | 17fcfc37 | Cristian Deluxe | # Return digit if regex are parsed correctly |
| 141 | # |
||
| 142 | d1d668f6 | Cristian Deluxe | # Return U (undefined) if any error occurs |
| 143 | 17fcfc37 | Cristian Deluxe | # |
| 144 | parseValue() {
|
||
| 145 | daf5b94a | Cristian Deluxe | # shellcheck disable=SC2155 |
| 146 | d1d668f6 | Cristian Deluxe | local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
|
| 147 | if [ -z "${TMP_RETURN}" ]; then
|
||
| 148 | echo 'U' |
||
| 149 | 17fcfc37 | Cristian Deluxe | else |
| 150 | echo "${TMP_RETURN}"
|
||
| 151 | fi |
||
| 152 | } |
||
| 153 | fe764769 | Kenyon Ralph | |
| 154 | 17fcfc37 | Cristian Deluxe | # Print results |
| 155 | d1d668f6 | Cristian Deluxe | for i in $FIELDS_ARR; do |
| 156 | printf "%s.value " "${i}"
|
||
| 157 | 48ab3322 | Cristian Deluxe | parseValue "${i}"
|
| 158 | done |
