From 8e5775ce333250681b1f4a61e8854a88020ab4bc Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 12:40:17 +0300 Subject: [PATCH 01/14] initial support for grep --- plugins/postfix/postfix_stats | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index d3e5ae91..86d0926f 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -61,6 +61,8 @@ GPLv2 #set -xv SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" +GREP_HOSTNAME=${0##*postfix_stats_} + # shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" [ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" @@ -86,7 +88,11 @@ fi # Config Section # if [ "$1" = 'config' ]; then - echo 'graph_title Postfix statistics' + if [ -n "${GREP_HOSTNAME}" ]; then + echo "graph_title Postfix statistics for ${GREP_HOSTNAME}" + else + echo 'graph_title Postfix statistics' + fi echo 'graph_vlabel Postfix statistics' echo 'graph_category mail' echo 'graph_scale no' @@ -110,7 +116,11 @@ fi # Variable to store the pflogsumm result. # shellcheck disable=SC2086 -TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG}) +if [ -n "${GREP_HOSTNAME}" ]; then + TMP_RAW=$(grep -h " ${GREP_HOSTNAME} postfix/" ${SYS_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) +else + TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}") +fi # Parse value from Raw result # From c2ddc35f731ac9a7fd85b6f5625783ddafa4d24f Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 12:46:17 +0300 Subject: [PATCH 02/14] quote --- plugins/postfix/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 86d0926f..315cd1a7 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -61,7 +61,7 @@ GPLv2 #set -xv SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" -GREP_HOSTNAME=${0##*postfix_stats_} +GREP_HOSTNAME="${0##*postfix_stats_}" # shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" From b13a180e92c2d4d37bf0bb95a2b17eca7dadda74 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 12:50:43 +0300 Subject: [PATCH 03/14] correct place for postfix logs is mail.log --- plugins/postfix/postfix_stats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 315cd1a7..7107c3dc 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -16,7 +16,7 @@ Any system where pflogsumm script can be executed. There is no default configuration. This is an example config for Ubuntu: [postfix_stats] - env.logfiles /var/log/syslog /var/log/syslog.1 + env.logfiles /var/log/mail.log /var/log/mail.log.1 env.pflogsumm pflogsumm env.logfiles contains space separated syslog logfiles, usually current log @@ -59,7 +59,7 @@ GPLv2 =cut #set -xv -SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" +SYS_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" GREP_HOSTNAME="${0##*postfix_stats_}" From bd0ff0947c44862f146b8aef9ee6ad4daecb2236 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 12:51:43 +0300 Subject: [PATCH 04/14] be more clear --- plugins/postfix/postfix_stats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 7107c3dc..34a35bca 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -59,7 +59,7 @@ GPLv2 =cut #set -xv -SYS_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" +MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" GREP_HOSTNAME="${0##*postfix_stats_}" @@ -117,9 +117,9 @@ fi # Variable to store the pflogsumm result. # shellcheck disable=SC2086 if [ -n "${GREP_HOSTNAME}" ]; then - TMP_RAW=$(grep -h " ${GREP_HOSTNAME} postfix/" ${SYS_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) + TMP_RAW=$(grep -h " ${GREP_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) else - TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}") + TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${MAIL_LOG}") fi # Parse value from Raw result From 335d856dfa9bb7579f2e3703fd5d6bdacac91633 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 13:04:00 +0300 Subject: [PATCH 05/14] mail.log is readable by root and adm group --- plugins/postfix/postfix_stats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 34a35bca..251d539d 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -15,7 +15,8 @@ Any system where pflogsumm script can be executed. There is no default configuration. This is an example config for Ubuntu: - [postfix_stats] + [postfix_stats*] + group adm env.logfiles /var/log/mail.log /var/log/mail.log.1 env.pflogsumm pflogsumm From 782097d72b409ada1d2420a8e5ce31025e106794 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 13:04:45 +0300 Subject: [PATCH 06/14] be more clever --- plugins/postfix/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 251d539d..44b737d4 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -62,7 +62,7 @@ GPLv2 #set -xv MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" -GREP_HOSTNAME="${0##*postfix_stats_}" +GREP_HOSTNAME=$(echo $0 | sed -r 's/^.+postfix_stats_?//') # shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" From b359073976a8cbe1bb8f46af562d888105a20091 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 13:09:29 +0300 Subject: [PATCH 07/14] unquote --- plugins/postfix/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 44b737d4..fc4271d0 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -120,7 +120,7 @@ fi if [ -n "${GREP_HOSTNAME}" ]; then TMP_RAW=$(grep -h " ${GREP_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) else - TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${MAIL_LOG}") + TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG}) fi # Parse value from Raw result From 1fe97cbfeb7ae43f51bc2c792112930766cf500a Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 13:36:17 +0300 Subject: [PATCH 08/14] add docs, bump version and credits --- plugins/postfix/postfix_stats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index fc4271d0..7f9eb007 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -28,6 +28,8 @@ env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually downloaded and installed, or "pflogsumm" if it was installed by a package manager (like apt-get). +Use the last part of the symlink name for grepping the hostname from log. + =head1 INTERPRETATION This plugin displays the messages: received, delivered, rejected... @@ -40,6 +42,7 @@ It is useful to know the load and messages being processed. #%# capabilities=autoconf =head1 VERSION + 0.3 support for hostname grep (useful when multiple hosts in one log) 0.2 plugin completely rewritten 0.1 first release. @@ -51,6 +54,7 @@ None known Originally: David Obando (david@cryptix.de) Modified by: github.com/cristiandeluxe +Modified by: github.com/4nd3r Thanks to: sumpfralle =head1 LICENSE From 81baaf697611971857849c2c3152e6ea78aa1daa Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Fri, 14 Apr 2017 17:30:36 +0300 Subject: [PATCH 09/14] be even more precise --- plugins/postfix/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 7f9eb007..b5509f4e 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -66,7 +66,7 @@ GPLv2 #set -xv MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" -GREP_HOSTNAME=$(echo $0 | sed -r 's/^.+postfix_stats_?//') +GREP_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//') # shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" From 390c8050276d87a33a91500c6992b2d293b1a33b Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Fri, 14 Apr 2017 17:31:49 +0300 Subject: [PATCH 10/14] more content-oriented name --- plugins/postfix/postfix_stats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index b5509f4e..12da3c9a 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -66,7 +66,7 @@ GPLv2 #set -xv MAIL_LOG="${logfiles:-/var/log/mail.log /var/log/mail.log.1}" -GREP_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//') +FILTER_HOSTNAME=$(basename "$0" | sed -r 's/postfix_stats_?//') # shellcheck disable=SC2154 PFLOGSUMM="${pflogsum}" @@ -93,8 +93,8 @@ fi # Config Section # if [ "$1" = 'config' ]; then - if [ -n "${GREP_HOSTNAME}" ]; then - echo "graph_title Postfix statistics for ${GREP_HOSTNAME}" + if [ -n "${FILTER_HOSTNAME}" ]; then + echo "graph_title Postfix statistics for ${FILTER_HOSTNAME}" else echo 'graph_title Postfix statistics' fi @@ -121,8 +121,8 @@ fi # Variable to store the pflogsumm result. # shellcheck disable=SC2086 -if [ -n "${GREP_HOSTNAME}" ]; then - TMP_RAW=$(grep -h " ${GREP_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) +if [ -n "${FILTER_HOSTNAME}" ]; then + TMP_RAW=$(grep -h " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) else TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG}) fi From b43f35f106e4f3cef6c3c8e7c7af887818d2a749 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Fri, 14 Apr 2017 17:36:37 +0300 Subject: [PATCH 11/14] fix shellcheck --- plugins/postfix/postfix_stats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 12da3c9a..82469b60 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -120,10 +120,11 @@ fi # # Variable to store the pflogsumm result. -# shellcheck disable=SC2086 if [ -n "${FILTER_HOSTNAME}" ]; then + # shellcheck disable=SC2086 TMP_RAW=$(grep -h " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) else + # shellcheck disable=SC2086 TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG}) fi From 56a367da728db3396be8f01c66e197f4d940e1fb Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Fri, 14 Apr 2017 17:44:15 +0300 Subject: [PATCH 12/14] add example --- plugins/postfix/postfix_stats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 82469b60..8bfb212b 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -30,6 +30,11 @@ manager (like apt-get). Use the last part of the symlink name for grepping the hostname from log. +For example: + + cd /etc/munin/plugins + ln -s /path/to/postfix_stats postfix_stats_HOSTNAME + =head1 INTERPRETATION This plugin displays the messages: received, delivered, rejected... From 16fcdeca9eda36acb95bdfaacc21cb6af923cdf0 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Sat, 15 Apr 2017 18:06:12 +0300 Subject: [PATCH 13/14] use fixed string --- plugins/postfix/postfix_stats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 8bfb212b..072435d4 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -127,7 +127,7 @@ fi # Variable to store the pflogsumm result. if [ -n "${FILTER_HOSTNAME}" ]; then # shellcheck disable=SC2086 - TMP_RAW=$(grep -h " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) + TMP_RAW=$(grep -Fh " ${FILTER_HOSTNAME} postfix/" ${MAIL_LOG} | "${PFLOGSUMM}" -d today --detail 0 --zero-fill) else # shellcheck disable=SC2086 TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${MAIL_LOG}) From ba37da55631df29d8be7b06aadb31fc51276b5ff Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Sat, 15 Apr 2017 18:12:48 +0300 Subject: [PATCH 14/14] clarify --- plugins/postfix/postfix_stats | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/postfix/postfix_stats b/plugins/postfix/postfix_stats index 072435d4..89ac0fdb 100755 --- a/plugins/postfix/postfix_stats +++ b/plugins/postfix/postfix_stats @@ -28,7 +28,9 @@ env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually downloaded and installed, or "pflogsumm" if it was installed by a package manager (like apt-get). -Use the last part of the symlink name for grepping the hostname from log. +Use the last part of the symlink name for filtering by hostname from logfile, +which contains logs from multiple hosts (e.g. received via rsyslog from remote +hosts). For example: