From c81c20ab3b60512ac86beaa0a0ea4dfafa76e1dd Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sat, 7 Apr 2018 02:11:05 +0200 Subject: [PATCH] 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) --- plugins/bind/bind9_resolver_stats | 4 +--- plugins/bind/bind9_server_stats | 8 +++----- plugins/bind/bind9_socket_stats | 8 +++----- plugins/nginx/nginx_error | 2 +- plugins/oracle/oracle_sysstat | 2 +- plugins/postgresql/pgbouncer_client_connections | 8 +++----- plugins/postgresql/pgbouncer_maxwait | 8 +++----- plugins/postgresql/pgbouncer_server_connections | 8 +++----- plugins/postgresql/postgresql_active_backends_by_database | 4 +--- plugins/solaris/forks | 2 +- plugins/solaris/fsstat_act_ | 2 +- plugins/solaris/fsstat_bytes | 2 +- plugins/solaris/interrupts | 2 +- plugins/solaris/io_disk | 2 +- plugins/streaming/packetship_ | 4 +--- plugins/weather/openweather_ | 2 +- plugins/wifi/wireless_channel_occupation_ | 2 +- plugins/wifi/wireless_signal_noise_ | 2 +- plugins/wifi/wireless_signal_ranges_ | 2 +- plugins/zfs/zfs_arcstats | 2 +- plugins/zfs/zpool_capacity | 2 +- plugins/znc/znc_logs.py | 2 +- 22 files changed, 32 insertions(+), 48 deletions(-) diff --git a/plugins/bind/bind9_resolver_stats b/plugins/bind/bind9_resolver_stats index 86e410d5..80f20373 100755 --- a/plugins/bind/bind9_resolver_stats +++ b/plugins/bind/bind9_resolver_stats @@ -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. diff --git a/plugins/bind/bind9_server_stats b/plugins/bind/bind9_server_stats index 4d495982..3c211e3c 100755 --- a/plugins/bind/bind9_server_stats +++ b/plugins/bind/bind9_server_stats @@ -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. diff --git a/plugins/bind/bind9_socket_stats b/plugins/bind/bind9_socket_stats index be742f33..f84261ed 100755 --- a/plugins/bind/bind9_socket_stats +++ b/plugins/bind/bind9_socket_stats @@ -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. diff --git a/plugins/nginx/nginx_error b/plugins/nginx/nginx_error index 9cb3d7df..6372867a 100755 --- a/plugins/nginx/nginx_error +++ b/plugins/nginx/nginx_error @@ -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 diff --git a/plugins/oracle/oracle_sysstat b/plugins/oracle/oracle_sysstat index 82159721..85ddd1f9 100755 --- a/plugins/oracle/oracle_sysstat +++ b/plugins/oracle/oracle_sysstat @@ -1119,7 +1119,7 @@ autoconf) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/postgresql/pgbouncer_client_connections b/plugins/postgresql/pgbouncer_client_connections index b179636e..0ba6e0ec 100755 --- a/plugins/postgresql/pgbouncer_client_connections +++ b/plugins/postgresql/pgbouncer_client_connections @@ -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: diff --git a/plugins/postgresql/pgbouncer_maxwait b/plugins/postgresql/pgbouncer_maxwait index bae7e8d8..a257ec6d 100755 --- a/plugins/postgresql/pgbouncer_maxwait +++ b/plugins/postgresql/pgbouncer_maxwait @@ -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: diff --git a/plugins/postgresql/pgbouncer_server_connections b/plugins/postgresql/pgbouncer_server_connections index ddd95964..6b63d2a9 100755 --- a/plugins/postgresql/pgbouncer_server_connections +++ b/plugins/postgresql/pgbouncer_server_connections @@ -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: diff --git a/plugins/postgresql/postgresql_active_backends_by_database b/plugins/postgresql/postgresql_active_backends_by_database index e4a53382..78a34745 100755 --- a/plugins/postgresql/postgresql_active_backends_by_database +++ b/plugins/postgresql/postgresql_active_backends_by_database @@ -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 diff --git a/plugins/solaris/forks b/plugins/solaris/forks index 5edf0a81..1744bdf3 100755 --- a/plugins/solaris/forks +++ b/plugins/solaris/forks @@ -98,7 +98,7 @@ autoconf) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/solaris/fsstat_act_ b/plugins/solaris/fsstat_act_ index c9113586..3332e0a8 100755 --- a/plugins/solaris/fsstat_act_ +++ b/plugins/solaris/fsstat_act_ @@ -163,7 +163,7 @@ suggest) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/solaris/fsstat_bytes b/plugins/solaris/fsstat_bytes index c95bfdfc..4fb5e7e1 100755 --- a/plugins/solaris/fsstat_bytes +++ b/plugins/solaris/fsstat_bytes @@ -160,7 +160,7 @@ autoconf) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/solaris/interrupts b/plugins/solaris/interrupts index d421004e..7f1f49cc 100755 --- a/plugins/solaris/interrupts +++ b/plugins/solaris/interrupts @@ -118,7 +118,7 @@ autoconf) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/solaris/io_disk b/plugins/solaris/io_disk index 3701d16b..34ec68f0 100755 --- a/plugins/solaris/io_disk +++ b/plugins/solaris/io_disk @@ -334,7 +334,7 @@ autoconf) ;; config) config - [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then fetch; fi ;; *) fetch diff --git a/plugins/streaming/packetship_ b/plugins/streaming/packetship_ index a9ec0964..b7465498 100755 --- a/plugins/streaming/packetship_ +++ b/plugins/streaming/packetship_ @@ -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. diff --git a/plugins/weather/openweather_ b/plugins/weather/openweather_ index ea232028..ffec4ea9 100755 --- a/plugins/weather/openweather_ +++ b/plugins/weather/openweather_ @@ -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" : '.*\