]> arthur.barton.de Git - netdata.git/blob - charts.d/postfix.chart.sh
strictier checking
[netdata.git] / charts.d / postfix.chart.sh
1 #!/bin/sh
2
3 postfix_postqueue=
4
5 postfix_check() {
6         # this should return:
7         #  - 0 to enable the chart
8         #  - 1 to disable the chart
9
10         # try to find the postqueue executable
11         if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
12         then
13                 postfix_postqueue="`which postqueue 2>/dev/null`"
14                 if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
15                 then
16                         local d=
17                         for d in /sbin /usr/sbin /usr/local/sbin
18                         do
19                                 if [ -x "$d/postqueue" ]
20                                 then
21                                         postfix_postqueue="$d/postqueue"
22                                         break
23                                 fi
24                         done
25                 fi
26         fi
27
28         if [ -z "$postfix_postqueue" -o ! -x  "$postfix_postqueue" ]
29         then
30                 echo >&2 "postfix: cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
31                 return 1
32         fi
33
34         return 0
35 }
36
37 postfix_create() {
38 cat <<EOF
39 CHART postfix.qemails '' "Postfix Queue Emails" "emails" postfix postfix line 5000 $update_every
40 DIMENSION emails '' absolute-no-interpolation 1 1
41 CHART postfix.qsize '' "Postfix Queue Emails Size" "emails size in KB" postfix postfix area 5001 $update_every
42 DIMENSION size '' absolute 1 1
43 EOF
44
45         return 0
46 }
47
48 postfix_update() {
49         # the first argument to this function is the microseconds since last update
50         # pass this parameter to the BEGIN statement (see bellow).
51
52         # do all the work to collect / calculate the values
53         # for each dimension
54         # remember: KEEP IT SIMPLE AND SHORT
55
56         # 1. execute postqueue -p
57         # 2. get the line that begins with --
58         # 3. match the 2 numbers on the line and output 2 lines like these:
59         #    local postfix_q_size=NUMBER
60         #    local postfix_q_emails=NUMBER
61         # 4. then execute this a script with the eval
62         #
63         # be very carefull with eval:
64         # prepare the script and always egrep at the end the lines that are usefull, so that
65         # even if something goes wrong, no other code can be executed
66         eval "`$postfix_postqueue -p |\
67                 grep "^--" |\
68                 sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" |\
69                 egrep "^local postfix_q_(emails|size)=[0-9]+$"`"
70
71         # write the result of the work.
72         cat <<VALUESEOF
73 BEGIN postfix.qemails $1
74 SET emails = $postfix_q_emails
75 END
76 BEGIN postfix.qsize $1
77 SET size = $postfix_q_size
78 END
79 VALUESEOF
80
81         return 0
82 }