Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / mail / postfix_stats @ 48ab3322

Historique | Voir | Annoter | Télécharger (2,11 ko)

1
#!/bin/sh
2
#
3
# Plugin to show Postfix statistics - needs pflogsumm
4
#
5
# Contributed by David Obando (david@cryptix.de) - 16.04.2007
6
# Rewrited by Cristian Deluxe (me@cristiandeluxe.com) - 02.11.2016
7
#
8
#
9
# Example config for Ubuntu (You need: apt-get install pflogsumm)
10
#
11
# [postfix_stats]
12
# env.logfile /var/log/syslog
13
# env.logfile2 /var/log/syslog.1
14
# env.pflogsumm pflogsumm
15
#
16
#
17
# Magic markers - optional - used by installation scripts and
18
# munin-config:
19
#
20
#%# family=contrib
21
#%# capabilities=autoconf
22

    
23
#set -xv
24
SYS_LOG=${logfile:-/var/log/syslog}
25
SYS_LOG2=${logfile2:-/var/log/syslog.0}
26
PFLOGSUMM=${pflogsumm:-pflogsumm.pl}
27

    
28
# Fields (Array to avoid code duplication)
29
declare -a FIELDS_ARR=("received" "delivered" "forwarded" "deferred" "bounced" "rejected" "held" "discarded")
30

    
31
#
32
# Autoconf Section
33
#
34
if [ "$1" = 'autoconf' ]; then
35
	# Try to find pflogsumm with default name
36
	PFLOG_EXIST=$(command -v pflogsumm.pl)
37

    
38
	# Try to find pflogsumm without any extension
39
	if [[ -z "${PFLOG_EXIST}" ]]
40
		then
41
		PFLOG_EXIST=$(command -v pflogsumm)
42
	fi
43

    
44
	if [[ -z "${PFLOG_EXIST}" ]]
45
		then
46
		echo 'no';
47
	else
48
		echo 'yes'
49
	fi
50
	exit 0;
51
fi
52

    
53
#
54
# Config Section
55
#
56
if [ "$1" = 'config' ]; then
57
	echo 'graph_title Postfix statistics'
58
	echo 'graph_vlabel Postfix statistics'
59
	echo 'graph_category mail'
60
	echo 'graph_scale no'
61
	echo 'graph_period minute'
62
	echo 'graph_total Total'
63

    
64
	# Generate config for each field
65
	for i in "${FIELDS_ARR[@]}"
66
	do
67
		echo "${i}.label ${i}"
68
		echo "${i}.type DERIVE"
69
		echo "${i}.min 0"
70
		echo "${i}.draw AREA"
71
	done
72

    
73
	exit 0
74
fi
75

    
76
#
77
# Plugin Script
78
#
79

    
80
# Variable to store the pflogsumm result.
81
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill "${SYS_LOG}" "${SYS_LOG2}")
82

    
83
# Parse value from Raw result
84
# 
85
# Return digit if regex are parsed correctly
86
#
87
# Return -1 if any error occurs
88
#
89
parseValue() {
90
	TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei '^[[:space:]]+[[:digit:]]+[[:space:]]+'"${1}"'.*$' | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
91
	if [[ -z "${TMP_RETURN}" ]]
92
		then
93
		echo -1
94
	else
95
		echo "${TMP_RETURN}"
96
	fi
97
}
98

    
99
# Print results
100
for i in "${FIELDS_ARR[@]}"
101
do
102
	printf "${i}.value "
103
	parseValue "${i}"
104
done