strictier checking
Costa Tsaousis (ktsaou) committed
May 21, 2014 at 00:33 UTC
9f4022b76a5b16ec258c4615287790d39dbbe154
2 files changed
+48
-18
charts.d/postfix.chart.sh
+18
-4
@@ -27,7 +27,7 @@ postfix_check() {
27
28
if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ]
29
then
30
- echo >&2 "Cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
30
+ echo >&2 "postfix: cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf"
31
return 1
32
fi
33
@@ -46,13 +46,27 @@ EOF
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
53
- eval `$postfix_postqueue -p | grep "^--" | sed -e "s/-- \([0-9]\+\) Kbytes in \([0-9]\+\) Requests.$/local postfix_q_size=\1\nlocal postfix_q_emails=\2/g" | grep "^local postfix_q_"`
54
- test -z "$postfix_q_emails" && local postfix_q_emails=0
55
- test -z "$postfix_q_size" && local postfix_q_size=0
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
charts.d/squid.chart.sh
+30
-14
@@ -7,7 +7,7 @@ squid_check() {
7
wget 2>/dev/null -O /dev/null "$squid_url"
8
if [ ! $? -eq 0 ]
9
then
10
- echo >&2 "squid: cannot fetch the url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
10
+ echo >&2 "squid: cannot fetch the counters url: $squid_url. Please set squid_url='url' in $confd/squid.conf"
11
return 1
12
fi
13
@@ -41,34 +41,50 @@ EOF
41
42
43
squid_update() {
44
+ # the first argument to this function is the microseconds since last update
45
+ # pass this parameter to the BEGIN statement (see bellow).
46
+
47
# do all the work to collect / calculate the values
48
# for each dimension
46
-
47
- # get the values from squid
48
- eval `wget 2>/dev/null -O - "$squid_url" | sed -e "s/\./_/g" -e "s/ = /=/g" | egrep "(^client_http_|^server_all_)"`
49
+ # remember: KEEP IT SIMPLE AND SHORT
50
+
51
+ # 1. wget the counters page from squid
52
+ # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local squid_
53
+ # 3. egrep lines starting with:
54
+ # local squid_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
55
+ # local squid_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
56
+ # 4. then execute this as a script with the eval
57
+ #
58
+ # be very carefull with eval:
59
+ # prepare the script and always grep at the end the lines that are usefull, so that
60
+ # even if something goes wrong, no other code can be executed
61
+
62
+ eval "`wget 2>/dev/null -O - "$squid_url" |\
63
+ sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/ = /=/g" -e "s/^/local squid_/g" |\
64
+ egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$"`"
65
66
# write the result of the work.
67
cat <<VALUESEOF
68
BEGIN squid.clients_net $1
53
-SET client_http_kbytes_in = $client_http_kbytes_in
54
-SET client_http_kbytes_out = $client_http_kbytes_out
55
-SET client_http_hit_kbytes_out = $client_http_hit_kbytes_out
69
+SET client_http_kbytes_in = $squid_client_http_kbytes_in
70
+SET client_http_kbytes_out = $squid_client_http_kbytes_out
71
+SET client_http_hit_kbytes_out = $squid_client_http_hit_kbytes_out
72
END
73
74
BEGIN squid.clients_requests $1
59
-SET client_http_requests = $client_http_requests
60
-SET client_http_hits = $client_http_hits
61
-SET client_http_errors = $client_http_errors
75
+SET client_http_requests = $squid_client_http_requests
76
+SET client_http_hits = $squid_client_http_hits
77
+SET client_http_errors = $squid_client_http_errors
78
END
79
80
BEGIN squid.servers_net $1
65
-SET server_all_kbytes_in = $server_all_kbytes_in
66
-SET server_all_kbytes_out = $server_all_kbytes_out
81
+SET server_all_kbytes_in = $squid_server_all_kbytes_in
82
+SET server_all_kbytes_out = $squid_server_all_kbytes_out
83
END
84
85
BEGIN squid.servers_requests $1
70
-SET server_all_requests = $server_all_requests
71
-SET server_all_errors = $server_all_errors
86
+SET server_all_requests = $squid_server_all_requests
87
+SET server_all_errors = $squid_server_all_errors
88
END
89
VALUESEOF
90