From 8e5775ce333250681b1f4a61e8854a88020ab4bc Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Thu, 13 Apr 2017 12:40:17 +0300 Subject: [PATCH] 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 #