-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcheck_postfix_mailqueue
executable file
·210 lines (195 loc) · 5.71 KB
/
check_postfix_mailqueue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
#
# Guillaume Subiron, Sysnove, 2016
# Inspired by Bjoern Bongermino's check_postfix_mailqueue
#
# Copyright 2016 Guillaume Subiron <[email protected]>
#
# GPL License: http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# Uncomment to enable debugging
# set -x
PROGNAME=$(basename "$0")
VERSION="Version 1.0"
AUTHOR="Guillaume Subiron (http://www.sysnove.fr/)"
STATE_OK=0
STATE_WARN=0
STATE_CRIT=2
STATE_UNKNOWN=3
warning=0
critical=0
config_dir="/etc/postfix"
print_version() {
echo "$PROGNAME $VERSION $AUTHOR"
}
print_help() {
print_version "$PROGNAME $VERSION"
echo ""
echo "$PROGNAME - Checks postfix mailqueue statistic"
echo ""
echo "$PROGNAME is a Nagios plugin which generates statistics"
echo "for the postfix mailqueue and checks for corrupt messages."
echo "The following values will be checked:"
echo "maildrop: Localy posted mail"
echo "incoming: Processed local mail and received from network"
echo "active: Mails being delivered (should be small)"
echo "deferred: Stuck mails (that will be retried later)"
echo "corrupt: Messages found to not be in correct format (should be 0)"
echo "hold: Recent addition, messages put on hold indefinitly - delete of free"
echo ""
echo "Usage: $PROGNAME --deferred_warn Deferred-WARN-Level --deferred_crit Deferred-CRIT-Level --active_warn Active-WARN-Level […]"
echo ""
echo "By default, all thresholds are 0 except corrupt_crit"
echo ""
echo "Options:"
echo " --deferred_warn)"
echo " Warning level for deferred mails"
echo " --deferred_crit)"
echo " Critical level for deferred mails"
echo " --active_warn)"
echo " Warning level for active mails"
echo " --active_crit)"
echo " Critical level for active mails"
echo " --maildrop_warn)"
echo " Warning level for maildrop mails"
echo " --maildrop_crit)"
echo " Critical level for maildrop mails"
echo " --incoming_warn)"
echo " Warning level for incoming mails"
echo " --incoming_crit)"
echo " Critical level for incoming mails"
echo " --corrupt_warn)"
echo " Warning level for corrupt mails"
echo " --corrupt_crit)"
echo " Critical level for corrupt mails (default=1)"
echo " --hold_warn)"
echo " Warning level for hold mails"
echo " --hold_crit)"
echo " Critical level for hold mails"
echo " --config_dir)"
echo " Postfix config directory (default=/etc/postfix)"
echo " -h)"
echo " This help"
echo " -v)"
echo " Version"
exit $STATE_OK
}
print_output() {
values=""
perfdata=""
for i in deferred active maildrop incoming corrupt hold; do
values="${values}${i^}=${!i} "
warn_var="${i}_warn"
crit_var="${i}_crit"
perfdata="$perfdata$i=${!i};${!warn_var};${!crit_var}; "
done
echo -n "Postfix Mailqueue $2 is $1 - $values| $perfdata"
}
# Check for parameters
while test -n "$1"; do
case "$1" in
-h)
print_help
exit $STATE_OK;;
-v)
print_version
exit $STATE_OK;;
--config_dir)
config_dir=$2
shift
;;
--deferred_warn)
deferred_warn=$2
shift
;;
--deferred_crit)
deferred_crit=$2
shift
;;
--active_warn)
active_warn=$2
shift
;;
--active_crit)
active_crit=$2
shift
;;
--maildrop_warn)
maildrop_warn=$2
shift
;;
--maildrop_crit)
maildrop_crit=$2
shift
;;
--incoming_warn)
incoming_warn=$2
shift
;;
--incoming_crit)
incoming_crit=$2
shift
;;
--corrupt_warn)
corrupt_warn=$2
shift
;;
--corrupt_crit)
corrupt_crit=$2
shift
;;
--hold_warn)
hold_warn=$2
shift
;;
--hold_crit)
hold_crit=$2
shift
;;
*)
print_help
;;
esac
shift
done
if [ -z "$corrupt_crit" ]; then
corrupt_crit=1
fi
# Can be set via environment, but default is fetched by postconf (if available,
# else /var/spool/postfix)
if which postconf > /dev/null ; then
SPOOLDIR=${spooldir:-$(postconf -c "$config_dir" -h queue_directory)}
else
SPOOLDIR=${spooldir:-/var/spool/postfix}
fi
cd "$SPOOLDIR" >/dev/null 2>/dev/null || {
echo -n "Cannot cd to $SPOOLDIR"
exit $STATE_CRIT
}
# Get values
for i in deferred active maildrop incoming corrupt hold; do
eval $i=`(test -d "$i" && find "$i" -type f ) | wc -l`
done
for state in crit warn; do
for i in deferred active maildrop incoming corrupt hold; do
threshold_var="${i}_${state}"
value=${!i}
threshold=${!threshold_var}
if [ -n "$threshold" ] && [ $value -ge $threshold ]; then
print_output ${state^^} $i
return_var="STATE_${state^^}"
exit ${!return_var}
fi
done
done
print_output OK
exit $STATE_OK