non-bash compatibility
Costa Tsaousis (ktsaou) committed
May 10, 2014 at 23:09 UTC
9e6c3a13ab12e86ea7c0712d5ff0b62dbab5642e
1 file changed
+41
-35
plugins.d/charts.d.plugin
+41
-35
@@ -14,6 +14,12 @@ myconfig="$confd/charts.d.conf"
14
minimum_update_frequency=1
15
update_every=1 # this is overwritten by the command line
16
17
+# work around for non BASH shells
18
+charts_create="_create"
19
+charts_update="_update"
20
+charts_check="_check"
21
+charts_undescore="_"
22
+
23
# -----------------------------------------------------------------------------
24
# parse parameters
25
@@ -137,60 +143,60 @@ all_enabled_charts() {
143
144
# find all enabled charts
145
140
- for x in `all_charts`
146
+ for chart in `all_charts`
147
do
142
- eval "enabled=\$$x"
148
+ eval "enabled=\$$chart"
149
if [ "$enabled" = "yes" ]
150
then
145
- local charts="$charts $x"
151
+ local charts="$charts $chart"
152
else
147
- echo >&2 "charts.d: chart '$x' is NOT enabled. Add a line with $x=yes in $myconfig to enable it."
153
+ echo >&2 "charts.d: chart '$chart' is NOT enabled. Add a line with $chart=yes in $myconfig to enable it."
154
fi
155
done
156
157
local charts2=
152
- for x in $charts
158
+ for chart in $charts
159
do
160
# check the enabled charts
155
- local check=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_check()"`
161
+ local check=`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_check()"`
162
if [ -z "$check" ]
163
then
158
- echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_check() function. Disabling it."
164
+ echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_check() function. Disabling it."
165
continue
166
fi
167
162
- local create=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_create()"`
168
+ local create=`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_create()"`
169
if [ -z "$create" ]
170
then
165
- echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_create() function. Disabling it."
171
+ echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_create() function. Disabling it."
172
continue
173
fi
174
169
- local update=`cat "$chartsd/$x.chart.sh" | sed "s/^ \+//g" | grep "^${x}_update()"`
175
+ local update=`cat "$chartsd/$chart.chart.sh" | sed "s/^ \+//g" | grep "^$chart$charts_update()"`
176
if [ -z "$update" ]
177
then
172
- echo >&2 "charts.d: chart '$x' does not seem to have a ${x}_update() function. Disabling it."
178
+ echo >&2 "charts.d: chart '$chart' does not seem to have a $chart$charts_update() function. Disabling it."
179
continue
180
fi
181
182
# check its config
177
- if [ -f "$confd/$x.conf" ]
183
+ if [ -f "$confd/$chart.conf" ]
184
then
179
- if [ ! -z "`cat "$confd/$x.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^${x}_"`" ]
185
+ if [ ! -z "`cat "$confd/$chart.conf" | sed "s/^ \+//g" | grep -v "^$" | grep -v "^#" | grep -v "^$chart$charts_undescore"`" ]
186
then
181
- echo >&2 "charts.d: chart's $x config $confd/$x.conf should only have lines starting with ${x}_ . Disabling it."
187
+ echo >&2 "charts.d: chart's $chart config $confd/$chart.conf should only have lines starting with $chart$charts_undescore . Disabling it."
188
continue
189
fi
190
fi
191
186
- "$pluginsd/charts.d.dryrun-helper.sh" "$x" "$chartsd/$x.chart.sh" "$confd/$x.conf" >/dev/null
192
+ "$pluginsd/charts.d.dryrun-helper.sh" "$chart" "$chartsd/$chart.chart.sh" "$confd/$chart.conf" >/dev/null
193
if [ $? -ne 0 ]
194
then
189
- echo >&2 "charts.d: chart's $x did not pass the dry run check. This means it uses global variables not starting with $x. Disabling it."
195
+ echo >&2 "charts.d: chart's $chart did not pass the dry run check. This means it uses global variables not starting with $chart. Disabling it."
196
continue
197
fi
198
193
- local charts2="$charts2 $x"
199
+ local charts2="$charts2 $chart"
200
done
201
202
echo $charts2
@@ -201,21 +207,21 @@ all_enabled_charts() {
207
# load the charts
208
209
active_charts=
204
-for x in `all_enabled_charts`
210
+for chart in `all_enabled_charts`
211
do
206
- . "$chartsd/$x.chart.sh"
212
+ . "$chartsd/$chart.chart.sh"
213
208
- if [ -f "$confd/$x.conf" ]
214
+ if [ -f "$confd/$chart.conf" ]
215
then
210
- . "$confd/$x.conf"
216
+ . "$confd/$chart.conf"
217
fi
218
213
- ${x}_check
219
+ $chart$charts_check
220
if [ $? -eq 0 ]
221
then
216
- active_charts="$active_charts $x"
222
+ active_charts="$active_charts $chart"
223
else
218
- echo >&2 "charts.d: chart '$x' check() function reports failure."
224
+ echo >&2 "charts.d: chart '$chart' check() function reports failure."
225
fi
226
done
227
@@ -231,11 +237,11 @@ test $debug -eq 1 && debug_time=tellwork
237
if [ ! -z "$chart_only" ]
238
then
239
check_charts=
234
- for x in $active_charts
240
+ for chart in $active_charts
241
do
236
- if [ "$x" = "$chart_only" ]
242
+ if [ "$chart" = "$chart_only" ]
243
then
238
- check_charts="$x"
244
+ check_charts="$chart"
245
break
246
fi
247
done
@@ -255,14 +261,14 @@ fi
261
# create charts
262
263
run_charts=
258
-for x in $active_charts
264
+for chart in $active_charts
265
do
260
- ${x}_create
266
+ $chart$charts_create
267
if [ $? -eq 0 ]
268
then
263
- run_charts="$run_charts $x"
269
+ run_charts="$run_charts $chart"
270
else
265
- echo >&2 "charts.d: chart '$x' create() function reports failure."
271
+ echo >&2 "charts.d: chart '$chart' create() function reports failure."
272
fi
273
done
274
@@ -274,14 +280,14 @@ do
280
now_charts=$run_charts
281
run_charts=
282
277
- for x in $now_charts
283
+ for chart in $now_charts
284
do
279
- ${x}_update
285
+ $chart$charts_update
286
if [ $? -eq 0 ]
287
then
282
- run_charts="$run_charts $x"
288
+ run_charts="$run_charts $chart"
289
else
284
- echo >&2 "charts.d: chart '$x' update() function reports failure. Disabling it."
290
+ echo >&2 "charts.d: chart '$chart' update() function reports failure. Disabling it."
291
fi
292
done
293