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