Projet

Général

Profil

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

root / plugins / postfix / postfix_stats @ 4b400a73

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

1
#!/bin/sh
2
# -*- sh -*-
3

    
4
: <<=cut
5

    
6
=head1 NAME
7

    
8
postfix_stats - Munin plugin to monitor postfix statistics.
9

    
10
=head1 APPLICABLE SYSTEMS
11

    
12
Any system where pflogsumm script can be executed.
13

    
14
=head1 CONFIGURATION
15

    
16
There is no default configuration. This is an example config for Ubuntu:
17

    
18
  [postfix_stats]
19
   env.logfiles /var/log/syslog /var/log/syslog.1
20
   env.pflogsumm pflogsumm
21

    
22
env.logfiles contains space separated syslog logfiles, usually current log
23
and previous log. You can add more log files if you want, but this may 
24
increase the time required for analysis.
25

    
26
env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually
27
downloaded and installed, or "pflogsumm" if it was installed by a package 
28
manager (like apt-get).
29

    
30
=head1 INTERPRETATION
31

    
32
This plugin displays the messages: received, delivered, rejected...
33
Average per minute is made and it shows the total message count.
34
It is useful to know the load and messages being processed.
35

    
36
=head1 MAGIC MARKERS
37

    
38
  #%# family=auto
39
  #%# capabilities=autoconf
40

    
41
=head1 VERSION
42
  0.2 plugin completely rewritten
43
  0.1 first release.
44

    
45
=head1 BUGS
46

    
47
None known
48

    
49
=head1 AUTHOR
50

    
51
Originally: David Obando (david@cryptix.de)
52
Modified by: github.com/cristiandeluxe
53
Thanks to: sumpfralle
54

    
55
=head1 LICENSE
56

    
57
GPLv2
58

    
59
=cut
60

    
61
#set -xv
62
SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}"
63

    
64
# shellcheck disable=SC2154
65
PFLOGSUMM="${pflogsum}"
66
[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)"
67

    
68
# Fields (Array to avoid code duplication) must be space separated
69
FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded"
70

    
71
#
72
# Autoconf Section
73
#
74
if [ "$1" = 'autoconf' ]; then
75
	# Check if pflogsumm exist
76
	if [ -z "${PFLOGSUMM}" ]
77
		then
78
		echo 'no (pflogsum not found in your system)'
79
	else
80
		echo 'yes'
81
	fi
82
	exit 0
83
fi
84

    
85
#
86
# Config Section
87
#
88
if [ "$1" = 'config' ]; then
89
	echo 'graph_title Postfix statistics'
90
	echo 'graph_vlabel Postfix statistics'
91
	echo 'graph_category mail'
92
	echo 'graph_scale no'
93
	echo 'graph_period minute'
94
	echo 'graph_total Total'
95

    
96
	# Generate config for each field
97
	for i in $FIELDS_ARR; do
98
		echo "${i}.label ${i}"
99
		echo "${i}.type DERIVE"
100
		echo "${i}.min 0"
101
		echo "${i}.draw AREASTACK"
102
	done
103

    
104
	exit 0
105
fi
106

    
107
#
108
# Plugin Script
109
#
110

    
111
# Variable to store the pflogsumm result.
112
# shellcheck disable=SC2086
113
TMP_RAW=$("${PFLOGSUMM}" -d today --detail 0 --zero-fill ${SYS_LOG})
114

    
115
# Parse value from Raw result
116
# 
117
# Return digit if regex are parsed correctly
118
#
119
# Return U (undefined) if any error occurs
120
#
121
parseValue() {
122
	# shellcheck disable=SC2155
123
	local TMP_RETURN=$(echo "${TMP_RAW}" | grep -Ei "^[[:space:]]+[[:digit:]]+[[:space:]]+${1}.*$" | grep -oEi '[[:digit:]]+[[:space:]]+' | head -n 1 | sed 's: ::g')
124
	if [ -z "${TMP_RETURN}" ]; then
125
		echo 'U'
126
	else
127
		echo "${TMP_RETURN}"
128
	fi
129
}
130

    
131
# Print results
132
for i in $FIELDS_ARR; do
133
	printf "%s.value " "${i}"
134
	parseValue "${i}"
135
done