unify DIRTYCONFIG handling in shell and python plugins

The following issues were fixed:
* comparison too broad (e.g. "0" misinterpreted as "true")
* python: comparing string with number (is never equal in python)
* unwanted non-zero exitcode (compound command "&&" as last command in
  shell code block (e.g. "case" or "if" branch))
* access to unset variable (shell style issue)
This commit is contained in:
Lars Kruse 2018-04-07 02:11:05 +02:00
parent 270be2f59e
commit c81c20ab3b
22 changed files with 32 additions and 48 deletions

View File

@ -72,9 +72,7 @@ if [ "$1" = "config" ]; then
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output the stats.

View File

@ -69,11 +69,9 @@ if [ "$1" = "config" ]; then
echo ${key}.type COUNTER
done
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output the stats.

View File

@ -67,11 +67,9 @@ if [ "$1" = "config" ]; then
echo ${key}.type COUNTER
done
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output the stats.

View File

@ -156,7 +156,7 @@ case ${1:-} in
config)
do_config
# support "dirty config" capability
if [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ]; then do_fetch; fi
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi
;;
autoconf)
do_autoconf

View File

@ -1119,7 +1119,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -46,11 +46,9 @@ if [ "$1" = "config" ]; then
echo ${pool}.type GAUGE
done
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output looks like this:

View File

@ -46,11 +46,9 @@ if [ "$1" = "config" ]; then
echo ${pool}.type GAUGE
done
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output looks like this:

View File

@ -46,11 +46,9 @@ if [ "$1" = "config" ]; then
echo ${pool}.type GAUGE
done
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# Output looks like this:

View File

@ -73,9 +73,7 @@ if [ "$1" = "config" ]; then
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
while read pool sep backends junk

View File

@ -98,7 +98,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -163,7 +163,7 @@ suggest)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -160,7 +160,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -118,7 +118,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -334,7 +334,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -108,9 +108,7 @@ if [ "$1" = "config" ]; then
# If dirty config capability is enabled then fall through
# to output the data with the config information.
if [ "$MUNIN_CAP_DIRTYCONFIG" = "" ]; then
exit 0
fi
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" != "1" ]; then exit 0; fi
fi
# If there are no pumps then output fake pump1 data and end.

View File

@ -83,7 +83,7 @@ then
EOF
# Continue if dirty config is enabled
[ "$MUNIN_CAP_DIRTYCONFIG" = 1 ] || exit 0
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] || exit 0
fi
TEMP_AVG=$( expr "$OWAPI" : '.*\<temperature value=\"\(.*\)\" min.*/temperature.*' )

View File

@ -135,7 +135,7 @@ elif [ "${1:-}" = "suggest" ]; then
done
elif [ "${1:-}" = "config" ]; then
do_config || exit 1
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] && do_fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi
else
do_fetch
fi

View File

@ -147,7 +147,7 @@ ACTION="${1:-}"
case "$ACTION" in
config)
do_config || exit 1
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] && do_fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi
;;
autoconf)
if [ -z "$(get_wifi_interfaces)" ]; then

View File

@ -138,7 +138,7 @@ ACTION="${1:-}"
case "$ACTION" in
config)
do_config || exit 1
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] && do_fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi
;;
autoconf)
[ -z "$(get_wifi_interfaces)" ] && echo "no (no wifi interfaces found)" && exit 1

View File

@ -351,7 +351,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -257,7 +257,7 @@ autoconf)
;;
config)
config
[ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi
;;
*)
fetch

View File

@ -159,7 +159,7 @@ def emit_config():
print('graph_period minute')
graph_order = []
if 'MUNIN_CAP_DIRTYCONFIG' in os.environ and os.environ['MUNIN_CAP_DIRTYCONFIG'] == 1:
if os.getenv('MUNIN_CAP_DIRTYCONFIG') == "1":
read_data(1)
else:
read_data(0)