This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcheck_postfix_queue
executable file
·120 lines (104 loc) · 2.63 KB
/
check_postfix_queue
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
#!/bin/sh
## 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 3 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.
##
## You should have received a copy of the GNU General Public License
## along with check_bacula.pl. If not, see <http://www.gnu.org/licenses/>.
# ===============
# check_postqueue - plugin to chech the length of postfix queue
# ===============
# * written by Silver Salonen, Estonia
# version 1.0.2 (16.Apr.2010)
# * bugfix: "NOT_" was still used - the change was done only in usage
# version 1.0.1 (28.Apr.2008)
# * replace ! with "NOT_" in as a negating command
# version 1.0 (21.Apr.2008)
# plugin return codes:
# 0 OK
# 1 Warning
# 2 Critical
# 3 Unknown
while getopts "hvw:c:f:" opt
do
case $opt in
h)
showhelp=1
break
;;
w)
warning="$OPTARG"
;;
c)
critical="$OPTARG"
;;
f)
from="$OPTARG"
;;
v)
verbose=1
;;
esac
done
postqueue="`which postqueue 2>/dev/null`"
if [ ! "$postqueue" ]; then
echo "Could not find postqueue!"
exit 3
fi
printUsage() {
echo "Usage: $0 [-h] [-v] -w <warning> -c <critical> [ -f <[!]from-address>]"
echo ""
echo "Example: $0 -w 50 -c 100 -f '!MAILER-DAEMON'"
}
printHelp() {
printUsage
echo ""
echo "This plugin checks the number of messages in Postfix queue."
echo "You may specify <from-address> to include messages only from the specific address or negate the result with '!', ie. '!<from-address>'."
echo ""
echo "For more details, see inside the script ;)"
echo ""
exit 3
}
getQueue () {
queue="`$postqueue -p | grep "^[A-Z0-9]" | grep -v "Mail queue is empty"`"
if [ "$from" ]; then
# $from begins with '!', so negate
if ( echo "$from" | grep '^!' > /dev/null ); then
from="-v `echo "$from" | sed 's/^!//'`"
fi
queue=`echo "$queue" | grep -i $from`
fi
if [ ! "$queue" ]; then
echo 0
else
echo "$queue" | wc -l | sed "s/^ *//"
fi
}
if [ "$showhelp" = "1" ]; then
printHelp
exit 3
fi
if [ ! "$warning" ] || [ ! "$critical" ]; then
printUsage
exit 3
fi
if [ $warning -ge $critical ]; then
echo "<warning> has to be smaller than <critical>!"
exit 3
fi
queue=`getQueue`
echo "Number of queued messages: $queue"
if [ "$queue" -ge "$critical" ]; then
exit 2
elif [ "$queue" -ge "$warning" ]; then
exit 1
else
exit 0
fi