Add special check to warn before customers get too high invoices
[infodrom/icinga-plugins] / check_postfix_queue
1 #!/bin/bash
2 #
3 # 19-07-2010
4 # Author: Cherwin Nooitmeer <cherwin@gmail.com>
5 #
6
7 # exit codes
8 e_ok=0
9 e_warning=1
10 e_critical=2
11 e_unknown=3
12
13 # regular expression that matches queue IDs (e.g. D71EF7AC80F8)
14 queue_id='^[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]'
15
16 usage="Invalid command line usage"
17
18 if [ -z $1 ]; then
19     echo $usage
20     exit $e_unknown
21 fi
22
23 while getopts ":w:c:" options
24 do
25     case $options in
26         w ) warning=$OPTARG ;;
27         c ) critical=$OPTARG ;;
28         * ) echo $usage
29             exit $e_unknown ;;
30     esac
31 done
32
33 # determine queue size
34 qsize=$(mailq | egrep -c $queue_id)
35 if [ -z $qsize ]
36 then
37     exit $e_unknown
38 fi
39
40 if [ $qsize -ge $critical ]; then
41     retval=$e_critical
42 elif [ $qsize -ge $warning ]; then
43     retval=$e_warning
44 elif [ $qsize -lt $warning ]; then
45     retval=$e_ok
46 fi
47
48 echo "$qsize mail(s) in queue | mail_queue=$qsize"
49 exit $retval