1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

no duplicated code, area graph, only first result

This commit is contained in:
Cristian Deluxe 2016-11-02 06:59:07 +01:00
parent 8e2025a9b9
commit 48ab33220e

View file

@ -25,6 +25,9 @@ SYS_LOG=${logfile:-/var/log/syslog}
SYS_LOG2=${logfile2:-/var/log/syslog.0} SYS_LOG2=${logfile2:-/var/log/syslog.0}
PFLOGSUMM=${pflogsumm:-pflogsumm.pl} PFLOGSUMM=${pflogsumm:-pflogsumm.pl}
# Fields (Array to avoid code duplication)
declare -a FIELDS_ARR=("received" "delivered" "forwarded" "deferred" "bounced" "rejected" "held" "discarded")
# #
# Autoconf Section # Autoconf Section
# #
@ -57,31 +60,17 @@ if [ "$1" = 'config' ]; then
echo 'graph_scale no' echo 'graph_scale no'
echo 'graph_period minute' echo 'graph_period minute'
echo 'graph_total Total' echo 'graph_total Total'
echo 'received.label received'
echo 'received.type DERIVE' # Generate config for each field
echo 'received.min 0' for i in "${FIELDS_ARR[@]}"
echo 'delivered.label delivered' do
echo 'delivered.type DERIVE' echo "${i}.label ${i}"
echo 'delivered.min 0' echo "${i}.type DERIVE"
echo 'forwarded.label forwarded' echo "${i}.min 0"
echo 'forwarded.type DERIVE' echo "${i}.draw AREA"
echo 'forwarded.min 0' done
echo 'deferred.label deferred'
echo 'deferred.type DERIVE' exit 0
echo 'deferred.min 0'
echo 'bounced.label bounced'
echo 'bounced.type DERIVE'
echo 'bounced.min 0'
echo 'rejected.label rejected'
echo 'rejected.type DERIVE'
echo 'rejected.min 0'
echo 'held.label held'
echo 'held.type DERIVE'
echo 'held.min 0'
echo 'discarded.label discarded'
echo 'discarded.type DERIVE'
echo 'discarded.min 0'
exit 0;
fi fi
# #
@ -98,7 +87,7 @@ TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG
# Return -1 if any error occurs # Return -1 if any error occurs
# #
parseValue() { parseValue() {
TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | sed 's: ::g') TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
if [[ -z "${TMP_RETURN}" ]] if [[ -z "${TMP_RETURN}" ]]
then then
echo -1 echo -1
@ -108,19 +97,8 @@ parseValue() {
} }
# Print results # Print results
printf 'received.value ' for i in "${FIELDS_ARR[@]}"
parseValue 'received' do
printf 'delivered.value ' printf "${i}.value "
parseValue 'delivered' parseValue "${i}"
printf 'forwarded.value ' done
parseValue 'forwarded'
printf 'deferred.value '
parseValue 'deferred'
printf 'bounced.value '
parseValue 'bounced'
printf 'rejected.value '
parseValue 'rejected'
printf 'held.value '
parseValue 'held'
printf 'discarded.value '
parseValue 'discarded'