Projet

Général

Profil

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

root / plugins / mail / postfix_stats @ 424b962e

Historique | Voir | Annoter | Télécharger (2,3 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=manual
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
#
29
# Autoconf Section
30
#
31
if [ "$1" = "autoconf" ]; then
32
	# Try to find pflogsumm with default name
33
	PFLOG_EXIST=$(command -v pflogsumm.pl)
34

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

    
41
	if [[ -z "${PFLOG_EXIST}" ]]
42
		then
43
		echo "no";
44
	else
45
		echo "yes"
46
	fi
47
	exit 0;
48
fi
49

    
50
#
51
# Config Section
52
#
53
if [ "$1" = "config" ]; then
54
	echo "system.type COUNTER"
55
	echo "graph_title Postfix statistics"
56
	echo "graph_vlabel Postfix statistics"
57
	echo "graph_category Mail"
58
	echo "graph_total Total"
59
	echo "received.label received"
60
	echo "delivered.label delivered"
61
	echo "forwarded.label forwarded"
62
	echo "deferred.label deferred"
63
	echo "bounced.label bounced"
64
	echo "rejected.label rejected"
65
	echo "held.label held"
66
	echo "discarded.label discarded"
67
	exit 0;
68
fi
69

    
70
#
71
# Plugin Script
72
#
73

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

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

    
93
# Print results
94
printf "received.value "
95
parseValue "received"
96
printf "delivered.value "
97
parseValue "delivered"
98
printf "forwarded.value "
99
parseValue "forwarded"
100
printf "deferred.value "
101
parseValue "deferred"
102
printf "bounced.value "
103
parseValue "bounced"
104
printf "rejected.value "
105
parseValue "rejected"
106
printf "held.value "
107
parseValue "held"
108
printf "discarded.value "
109
parseValue "discarded"