]> arthur.barton.de Git - netdata.git/blob - plugins.d/charts.d.dryrun-helper.sh
ab-debian 0.20170327.01-0ab1, upstream v1.6.0-42-gaa6b96fc
[netdata.git] / plugins.d / charts.d.dryrun-helper.sh
1 #!/usr/bin/env bash
2
3 # will stop the script for any error
4 set -e
5
6 me="$0"
7 name="$1"
8 chart="$2"
9 conf="$3"
10
11 can_diff=1
12
13 tmp1="`mktemp`"
14 tmp2="`mktemp`"
15
16 myset() {
17     set | grep -v "^_=" | grep -v "^PIPESTATUS=" | grep -v "^BASH_LINENO="
18 }
19
20 # save 2 'set'
21 myset >"$tmp1"
22 myset >"$tmp2"
23
24 # make sure they don't differ
25 diff "$tmp1" "$tmp2" >/dev/null 2>&1
26 if [ $? -ne 0 ]
27 then
28     # they differ, we cannot do the check
29     echo >&2 "$me: cannot check with diff."
30     can_diff=0
31 fi
32
33 # do it again, now including the script
34 myset >"$tmp1"
35
36 # include the plugin and its config
37 if [ -f "$conf" ]
38 then
39     . "$conf"
40     if [ $? -ne 0 ]
41     then
42         echo >&2 "$me: cannot load config file $conf"
43         rm "$tmp1" "$tmp2"
44         exit 1
45     fi
46 fi
47
48 . "$chart"
49 if [ $? -ne 0 ]
50 then
51     echo >&2 "$me: cannot load chart file $chart"
52     rm "$tmp1" "$tmp2"
53     exit 1
54 fi
55
56 # remove all variables starting with the plugin name
57 myset | grep -v "^$name" >"$tmp2"
58
59 if [ $can_diff -eq 1 ]
60 then
61     # check if they are different
62     # make sure they don't differ
63     diff "$tmp1" "$tmp2" >&2
64     if [ $? -ne 0 ]
65     then
66         # they differ
67         rm "$tmp1" "$tmp2"
68         exit 1
69     fi
70 fi
71
72 rm "$tmp1" "$tmp2"
73 exit 0