diff options
author | Paweł Krupa <pawel@krupa.net.pl> | 2018-09-29 01:09:34 +0200 |
---|---|---|
committer | Costa Tsaousis <costa@tsaousis.gr> | 2018-09-29 02:09:34 +0300 |
commit | a1b6a7f5328974aaddd7f631135c58e1d620c820 (patch) | |
tree | f834274490755daeddc0b445e9c75d18b71b88e1 /charts.d | |
parent | 986e32a03b2f01ac09b23d7f1be28a2799d7fd3b (diff) |
[cleanup crusade] Shellcheck (#4261)
* lint libreswan module
* disable linting obsolete shell modules
* shellcheck more shell modules
* fix review; lint helper scripts
* more shellcheck
* fix SC2235 in apache.chart.sh
* shellcheck last portion of charts.d scripts
* final shellcheck; make travis blocking
* fix cppcheck
* fix indents; fix expansion
* fix local var assignments
Diffstat (limited to 'charts.d')
-rw-r--r-- | charts.d/apache.chart.sh | 5 | ||||
-rw-r--r-- | charts.d/cpu_apps.chart.sh | 2 | ||||
-rw-r--r-- | charts.d/libreswan.chart.sh | 8 | ||||
-rw-r--r-- | charts.d/load_average.chart.sh | 2 | ||||
-rw-r--r-- | charts.d/mem_apps.chart.sh | 2 | ||||
-rw-r--r-- | charts.d/mysql.chart.sh | 25 | ||||
-rw-r--r-- | charts.d/nginx.chart.sh | 48 | ||||
-rw-r--r-- | charts.d/nut.chart.sh | 19 | ||||
-rw-r--r-- | charts.d/opensips.chart.sh | 9 | ||||
-rw-r--r-- | charts.d/phpfpm.chart.sh | 17 | ||||
-rw-r--r-- | charts.d/postfix.chart.sh | 12 | ||||
-rw-r--r-- | charts.d/sensors.chart.sh | 110 | ||||
-rw-r--r-- | charts.d/squid.chart.sh | 20 | ||||
-rw-r--r-- | charts.d/tomcat.chart.sh | 4 |
14 files changed, 157 insertions, 126 deletions
diff --git a/charts.d/apache.chart.sh b/charts.d/apache.chart.sh index 779a4026a0..84d4e1bf07 100644 --- a/charts.d/apache.chart.sh +++ b/charts.d/apache.chart.sh @@ -103,7 +103,10 @@ apache_get() { ret=$? IFS="${oIFS}" - ([ $ret -ne 0 ] || [ "${#apache_response[@]}" -eq 0 ]) && return 1 + if [ $ret -ne 0 ] || [ "${#apache_response[@]}" -eq 0 ] + then + return 1 + fi # the last line on the apache output is "Scoreboard" # we use this label to detect that the output has a new word count diff --git a/charts.d/cpu_apps.chart.sh b/charts.d/cpu_apps.chart.sh index f287dba431..2d83db7bb3 100644 --- a/charts.d/cpu_apps.chart.sh +++ b/charts.d/cpu_apps.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC2154,SC1072,SC1073,SC2009,SC2162,SC2006,SC2002,SC2086,SC1117 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ diff --git a/charts.d/libreswan.chart.sh b/charts.d/libreswan.chart.sh index f2c4b210e5..4cfc3c3f0e 100644 --- a/charts.d/libreswan.chart.sh +++ b/charts.d/libreswan.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC1117 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ @@ -61,7 +61,8 @@ libreswan_get() { libreswan_connected_tunnels=() # convert the ipsec command output to a shell script - # and source it to get the values + # and source it to get the values + # shellcheck disable=SC1090 source <( { libreswan_ipsec whack --status; @@ -86,6 +87,7 @@ libreswan_check() { require_cmd ipsec || return 1 # make sure it is libreswan + # shellcheck disable=SC2143 if [ -z "$(ipsec --version | grep -i libreswan)" ] then error "ipsec command is not Libreswan. Disabling Libreswan plugin." @@ -141,7 +143,7 @@ libreswan_update_one() { [ -z "${id}" ] && libreswan_create_one "${name}" - uptime=$(( ${libreswan_now} - ${libreswan_established_add_time[${n}]} )) + uptime=$(( libreswan_now - libreswan_established_add_time[${n}] )) [ ${uptime} -lt 0 ] && uptime=0 # write the result of the work. diff --git a/charts.d/load_average.chart.sh b/charts.d/load_average.chart.sh index 41c5c22f13..f984e57861 100644 --- a/charts.d/load_average.chart.sh +++ b/charts.d/load_average.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC2154,SC1072,SC1073,SC2009,SC2162,SC2006,SC2002,SC2086,SC1117 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ diff --git a/charts.d/mem_apps.chart.sh b/charts.d/mem_apps.chart.sh index 9157ba1f79..ca79f60118 100644 --- a/charts.d/mem_apps.chart.sh +++ b/charts.d/mem_apps.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC2154,SC1072,SC1073,SC2009,SC2162,SC2006,SC2002,SC2086,SC1117 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ diff --git a/charts.d/mysql.chart.sh b/charts.d/mysql.chart.sh index 3b64d696a9..9008643a7a 100644 --- a/charts.d/mysql.chart.sh +++ b/charts.d/mysql.chart.sh @@ -26,7 +26,8 @@ mysql_get() { IFS=$'\t'$'\n' #arr=($(run "${@}" -e "SHOW GLOBAL STATUS WHERE value REGEXP '^[0-9]';" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)" )) #arr=($(run "${@}" -N -e "SHOW GLOBAL STATUS;" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)[^ ]+\s[0-9]" )) - arr=($(run "${@}" -N -e "SHOW GLOBAL STATUS;" | egrep "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)[^[:space:]]+[[:space:]]+[0-9]+" )) + # shellcheck disable=SC2207 + arr=($(run "${@}" -N -e "SHOW GLOBAL STATUS;" | grep -E "^(Bytes|Slow_|Que|Handl|Table|Selec|Sort_|Creat|Conne|Abort|Binlo|Threa|Innod|Qcach|Key_|Open)[^[:space:]]+[[:space:]]+[0-9]+" )) IFS="${oIFS}" [ "${#arr[@]}" -lt 3 ] && return 1 @@ -56,6 +57,7 @@ mysql_check() { shift fi + # shellcheck disable=SC2230 [ -z "${mysql_cmd}" ] && mysql_cmd="$(which mysql 2>/dev/null || command -v mysql 2>/dev/null)" if [ ${#mysql_opts[@]} -eq 0 ] @@ -81,16 +83,18 @@ mysql_check() { [ -z "${mysql_cmds[$m]}" ] && mysql_cmds[$m]="$mysql_cmd" if [ -z "${mysql_cmds[$m]}" ] then - error "cannot get mysql command for '$m'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf" + # shellcheck disable=SC2154 + error "cannot get mysql command for '${m}'. Please set mysql_cmds[$m]='/path/to/mysql', in $confd/mysql.conf" fi mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]} + # shellcheck disable=SC2181 if [ ! $? -eq 0 ] then error "cannot get global status for '$m'. Please set mysql_opts[$m]='options' to whatever needed to get connected to the mysql server, in $confd/mysql.conf" - unset mysql_cmds[$m] - unset mysql_opts[$m] - unset mysql_ids[$m] + unset "mysql_cmds[$m]" + unset "mysql_opts[$m]" + unset "mysql_ids[$m]" continue fi @@ -99,7 +103,7 @@ mysql_check() { if [ ${#mysql_opts[@]} -eq 0 ] then - if [ ${unconfigured} -eq 1 -a ${tryroot} -eq 0 ] + if [ ${unconfigured} -eq 1 ] && [ ${tryroot} -eq 0 ] then mysql_check tryroot "${@}" return $? @@ -320,12 +324,13 @@ mysql_update() { x="${mysql_ids[$m]}" mysql_get "${mysql_cmds[$m]}" ${mysql_opts[$m]} + # shellcheck disable=SC2181 if [ $? -ne 0 ] then - unset mysql_ids[$m] - unset mysql_opts[$m] - unset mysql_cmds[$m] - error "failed to get values for '$m', disabling it." + unset "mysql_ids[$m]" + unset "mysql_opts[$m]" + unset "mysql_cmds[$m]" + error "failed to get values for '${m}', disabling it." continue fi diff --git a/charts.d/nginx.chart.sh b/charts.d/nginx.chart.sh index b626be7e6c..8e7c2c6f5a 100644 --- a/charts.d/nginx.chart.sh +++ b/charts.d/nginx.chart.sh @@ -27,20 +27,21 @@ nginx_reading=0 nginx_writing=0 nginx_waiting=0 nginx_get() { + # shellcheck disable=SC2207 nginx_response=($(run curl -Ss ${nginx_curl_opts} "${nginx_url}")) - [ $? -ne 0 -o "${#nginx_response[@]}" -eq 0 ] && return 1 - - if [ "${nginx_response[0]}" != "Active" \ - -o "${nginx_response[1]}" != "connections:" \ - -o "${nginx_response[3]}" != "server" \ - -o "${nginx_response[4]}" != "accepts" \ - -o "${nginx_response[5]}" != "handled" \ - -o "${nginx_response[6]}" != "requests" \ - -o "${nginx_response[10]}" != "Reading:" \ - -o "${nginx_response[12]}" != "Writing:" \ - -o "${nginx_response[14]}" != "Waiting:" \ - ] - then + # shellcheck disable=SC2181 + if [ $? -ne 0 ] || [ "${#nginx_response[@]}" -eq 0 ]; then return 1; fi + + if [ "${nginx_response[0]}" != "Active" ] ||\ + [ "${nginx_response[1]}" != "connections:" ] ||\ + [ "${nginx_response[3]}" != "server" ] ||\ + [ "${nginx_response[4]}" != "accepts" ] ||\ + [ "${nginx_response[5]}" != "handled" ] ||\ + [ "${nginx_response[6]}" != "requests" ] ||\ + [ "${nginx_response[10]}" != "Reading:" ] ||\ + [ "${nginx_response[12]}" != "Writing:" ] ||\ + [ "${nginx_response[14]}" != "Waiting:" ] + then error "Invalid response from nginx server: ${nginx_response[*]}" return 1 fi @@ -53,15 +54,14 @@ nginx_get() { nginx_writing="${nginx_response[13]}" nginx_waiting="${nginx_response[15]}" - if [ -z "${nginx_active_connections}" \ - -o -z "${nginx_accepts}" \ - -o -z "${nginx_handled}" \ - -o -z "${nginx_requests}" \ - -o -z "${nginx_reading}" \ - -o -z "${nginx_writing}" \ - -o -z "${nginx_waiting}" \ - ] - then + if [ -z "${nginx_active_connections}" ] ||\ + [ -z "${nginx_accepts}" ] ||\ + [ -z "${nginx_handled}" ] ||\ + [ -z "${nginx_requests}" ] ||\ + [ -z "${nginx_reading}" ] ||\ + [ -z "${nginx_writing}" ] ||\ + [ -z "${nginx_waiting}" ] + then error "empty values got from nginx server: ${nginx_response[*]}" return 1 fi @@ -73,8 +73,10 @@ nginx_get() { nginx_check() { nginx_get + # shellcheck disable=2181 if [ $? -ne 0 ] - then + then + # shellcheck disable=SC2154 error "cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf" return 1 fi diff --git a/charts.d/nut.chart.sh b/charts.d/nut.chart.sh index 07f571bdc0..af9f63e1db 100644 --- a/charts.d/nut.chart.sh +++ b/charts.d/nut.chart.sh @@ -56,21 +56,23 @@ nut_check() { for x in $nut_ups do nut_get "$x" >/dev/null + # shellcheck disable=SC2181 if [ $? -eq 0 ] + then + if [ ! -z "${nut_names[${x}]}" ] then - if [ ! -z "${nut_names[${x}]}" ] - then - nut_ids[$x]="$( fixid "${nut_names[${x}]}" )" - else - nut_ids[$x]="$( fixid "$x" )" - fi + nut_ids[$x]="$( fixid "${nut_names[${x}]}" )" + else + nut_ids[$x]="$( fixid "$x" )" + fi continue fi error "cannot get information for NUT UPS '$x'." done if [ ${#nut_ids[@]} -eq 0 ] - then + then + # shellcheck disable=SC2154 error "Cannot find UPSes - please set nut_ups='ups_name' in $confd/nut.conf" return 1 fi @@ -230,7 +232,8 @@ END { print \"END\" } }" - [ $? -ne 0 ] && unset nut_ids[$i] && error "failed to get values for '$i', disabling it." + # shellcheck disable=2181 + [ $? -ne 0 ] && unset "nut_ids[$i]" && error "failed to get values for '$i', disabling it." done [ ${#nut_ids[@]} -eq 0 ] && error "no UPSes left active." && return 1 diff --git a/charts.d/opensips.chart.sh b/charts.d/opensips.chart.sh index ed04044def..6385717fa8 100644 --- a/charts.d/opensips.chart.sh +++ b/charts.d/opensips.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC1117,SC2154,SC2086 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ @@ -35,8 +35,10 @@ opensips_check() { fi # check once if the command works - local x="$(opensips_get_stats | grep "^opensips_core_")" - if [ ! $? -eq 0 -o -z "$x" ] + local x + x="$(opensips_get_stats | grep "^opensips_core_")" + # shellcheck disable=SC2181 + if [ ! $? -eq 0 ] || [ -z "$x" ] then error "cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf" return 1 @@ -219,6 +221,7 @@ opensips_update() { opensips_command_failed=0 eval "local $(opensips_get_stats)" + # shellcheck disable=SC2181 [ $? -ne 0 ] && return 1 [ $opensips_command_failed -eq 1 ] && error "failed to get values, disabling." && return 1 diff --git a/charts.d/phpfpm.chart.sh b/charts.d/phpfpm.chart.sh index b169856b2f..ccf0eecdfd 100644 --- a/charts.d/phpfpm.chart.sh +++ b/charts.d/phpfpm.chart.sh @@ -37,8 +37,12 @@ phpfpm_slow_requests=0 phpfpm_get() { local opts="${1}" url="${2}" + # shellcheck disable=SC2207,2086 phpfpm_response=($(run curl -Ss ${opts} "${url}")) - [ $? -ne 0 -o "${#phpfpm_response[@]}" -eq 0 ] && return 1 + # shellcheck disable=SC2181 + if [ $? -ne 0 ] || [ "${#phpfpm_response[@]}" -eq 0 ]; then + return 1 + fi if [[ "${phpfpm_response[0]}" != "pool:" \ || "${phpfpm_response[2]}" != "process" \ @@ -105,9 +109,11 @@ phpfpm_check() { for m in "${!phpfpm_urls[@]}" do phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}" + # shellcheck disable=SC2181 if [ $? -ne 0 ]; then - error "cannot find status on URL '${phpfpm_url[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf" - unset phpfpm_urls[$m] + # shellcheck disable=SC2154 + error "cannot find status on URL '${phpfpm_urls[$m]}'. Please set phpfpm_urls[$m]='http://localhost/status' in $confd/phpfpm.conf" + unset "phpfpm_urls[$m]" continue fi done @@ -163,6 +169,7 @@ phpfpm_update() { for m in "${!phpfpm_urls[@]}" do phpfpm_get "${phpfpm_curl_opts[$m]}" "${phpfpm_urls[$m]}" + # shellcheck disable=SC2181 if [ $? -ne 0 ]; then continue fi @@ -189,7 +196,3 @@ EOF return 0 } - -phpfpm_check -phpfpm_create -phpfpm_update diff --git a/charts.d/postfix.chart.sh b/charts.d/postfix.chart.sh index 524f1b2533..e0a7727d9e 100644 --- a/charts.d/postfix.chart.sh +++ b/charts.d/postfix.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC1117 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ @@ -22,13 +22,15 @@ postfix_check() { # - 1 to disable the chart # try to find the postqueue executable - if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ] + if [ -z "$postfix_postqueue" ] || [ ! -x "$postfix_postqueue" ] then + # shellcheck disable=SC2230 postfix_postqueue="$(which postqueue 2>/dev/null || command -v postqueue 2>/dev/null)" fi - if [ -z "$postfix_postqueue" -o ! -x "$postfix_postqueue" ] + if [ -z "$postfix_postqueue" ] || [ ! -x "$postfix_postqueue" ] then + # shellcheck disable=SC2154 error "cannot find postqueue. Please set 'postfix_postqueue=/path/to/postqueue' in $confd/postfix.conf" return 1 fi @@ -68,10 +70,10 @@ postfix_update() { postfix_q_emails=0 postfix_q_size=0 - eval "$(run $postfix_postqueue -p |\ + eval "$(run "$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" |\ - egrep "^local postfix_q_(emails|size)=[0-9]+$")" + grep -E "^local postfix_q_(emails|size)=[0-9]+$")" # write the result of the work. cat <<VALUESEOF diff --git a/charts.d/sensors.chart.sh b/charts.d/sensors.chart.sh index 1a7a8f71c5..ded1e0bee5 100644 --- a/charts.d/sensors.chart.sh +++ b/charts.d/sensors.chart.sh @@ -33,13 +33,14 @@ sensors_priority=90000 declare -A sensors_excluded=() sensors_find_all_files() { - find $1 -maxdepth $sensors_sys_depth -name \*_input -o -name temp 2>/dev/null + find "$1" -maxdepth $sensors_sys_depth -name \*_input -o -name temp 2>/dev/null } sensors_find_all_dirs() { - sensors_find_all_files $1 | while read + # shellcheck disable=SC2162 + sensors_find_all_files "$1" | while read do - dirname $REPLY + dirname "$REPLY" done | sort -u } @@ -50,7 +51,7 @@ sensors_check() { # - 0 to enable the chart # - 1 to disable the chart - [ -z "$( sensors_find_all_files $sensors_sys_dir )" ] && error "no sensors found in '$sensors_sys_dir'." && return 1 + [ -z "$( sensors_find_all_files "$sensors_sys_dir" )" ] && error "no sensors found in '$sensors_sys_dir'." && return 1 return 0 } @@ -58,15 +59,15 @@ sensors_check_files() { # we only need sensors that report a non-zero value # also remove not needed sensors - local f= v= excluded= - for f in $* + local f v excluded + for f in "$@" do [ ! -f "$f" ] && continue - for ex in ${sensors_excluded[@]}; do + for ex in "${sensors_excluded[@]}"; do [[ $f =~ .*$ex$ ]] && excluded='1' && break done - [ "$excluded" != "1" ] && v="$( cat $f )" || v=0 + [ "$excluded" != "1" ] && v="$( cat "$f" )" || v=0 v=$(( v + 1 - 1 )) [ $v -ne 0 ] && echo "$f" && continue excluded= @@ -79,14 +80,15 @@ sensors_check_temp_type() { # valid temp types are 1 to 6 # disabled sensors have the value 0 - local f= t= v= - for f in $* + local f t v + for f in "$@" do - t=$( echo $f | sed "s|_input$|_type|g" ) + # shellcheck disable=SC2001 + t=$( echo "$f" | sed "s|_input$|_type|g" ) [ "$f" = "$t" ] && echo "$f" && continue [ ! -f "$t" ] && echo "$f" && continue - v="$( cat $t )" + v="$( cat "$t" )" v=$(( v + 1 - 1 )) [ $v -ne 0 ] && echo "$f" && continue @@ -96,34 +98,34 @@ sensors_check_temp_type() { # _create is called once, to create the charts sensors_create() { - local path= dir= name= x= file= lfile= labelname= labelid= device= subsystem= id= type= mode= files= multiplier= divisor= + local path dir name x file lfile labelname device subsystem id type mode files multiplier divisor # we create a script with the source of the # sensors_update() function # - the highest speed we can achieve - - [ $sensors_source_update -eq 1 ] && echo >$TMP_DIR/sensors.sh "sensors_update() {" + [ $sensors_source_update -eq 1 ] && echo >"$TMP_DIR/sensors.sh" "sensors_update() {" - for path in $( sensors_find_all_dirs $sensors_sys_dir | sort -u ) + for path in $( sensors_find_all_dirs "$sensors_sys_dir" | sort -u ) do - dir=$( basename $path ) + dir=$( basename "$path" ) device= subsystem= id= type= name= - [ -h $path/device ] && device=$( readlink -f $path/device ) - [ ! -z "$device" ] && device=$( basename $device ) + [ -h "$path/device" ] && device=$( readlink -f "$path/device" ) + [ ! -z "$device" ] && device=$( basename "$device" ) [ -z "$device" ] && device="$dir" - [ -h $path/subsystem ] && subsystem=$( readlink -f $path/subsystem ) - [ ! -z "$subsystem" ] && subsystem=$( basename $subsystem ) + [ -h "$path/subsystem" ] && subsystem=$( readlink -f "$path/subsystem" ) + [ ! -z "$subsystem" ] && subsystem=$( basename "$subsystem" ) [ -z "$subsystem" ] && subsystem="$dir" - [ -f $path/name ] && name=$( cat $path/name ) + [ -f "$path/name" ] && name=$( cat "$path/name" ) [ -z "$name" ] && name="$dir" - [ -f $path/type ] && type=$( cat $path/type ) + [ -f "$path/type" ] && type=$( cat "$path/type" ) [ -z "$type" ] && type="$dir" id="$( fixid "$device.$subsystem.$dir" )" @@ -139,66 +141,66 @@ sensors_create() { case $mode in temperature) - files="$( ls $path/temp*_input 2>/dev/null; ls $path/temp 2>/dev/null )" - files="$( sensors_check_files $files )" - files="$( sensors_check_temp_type $files )" + files="$( ls "$path"/temp*_input 2>/dev/null; ls "$path/temp" 2>/dev/null )" + files="$( sensors_check_files "$files" )" + files="$( sensors_check_temp_type "$files" )" [ -z "$files" ] && continue echo "CHART sensors.temp_$id '' '$name Temperature' 'Celsius' 'temperature' 'sensors.temp' line $((sensors_priority + 1)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.temp_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.temp_$id \$1\"" divisor=1000 ;; voltage) - files="$( ls $path/in*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/in*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.volt_$id '' '$name Voltage' 'Volts' 'voltage' 'sensors.volt' line $((sensors_priority + 2)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.volt_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.volt_$id \$1\"" divisor=1000 ;; current) - files="$( ls $path/curr*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/curr*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.curr_$id '' '$name Current' 'Ampere' 'current' 'sensors.curr' line $((sensors_priority + 3)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.curr_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.curr_$id \$1\"" divisor=1000 ;; power) - files="$( ls $path/power*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/power*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.power_$id '' '$name Power' 'Watt' 'power' 'sensors.power' line $((sensors_priority + 4)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.power_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.power_$id \$1\"" divisor=1000000 ;; fans) - files="$( ls $path/fan*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/fan*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.fan_$id '' '$name Fans Speed' 'Rotations / Minute' 'fans' 'sensors.fans' line $((sensors_priority + 5)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.fan_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.fan_$id \$1\"" ;; energy) - files="$( ls $path/energy*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/energy*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.energy_$id '' '$name Energy' 'Joule' 'energy' 'sensors.energy' areastack $((sensors_priority + 6)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.energy_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.energy_$id \$1\"" algorithm="incremental" divisor=1000000 ;; humidity) - files="$( ls $path/humidity*_input 2>/dev/null )" - files="$( sensors_check_files $files )" + files="$( ls "$path"/humidity*_input 2>/dev/null )" + files="$( sensors_check_files "$files" )" [ -z "$files" ] && continue echo "CHART sensors.humidity_$id '' '$name Humidity' 'Percent' 'humidity' 'sensors.humidity' line $((sensors_priority + 7)) $sensors_update_every" - echo >>$TMP_DIR/sensors.sh "echo \"BEGIN sensors.humidity_$id \$1\"" + echo >>"$TMP_DIR/sensors.sh" "echo \"BEGIN sensors.humidity_$id \$1\"" divisor=1000 ;; @@ -211,26 +213,27 @@ sensors_create() { do file="$x" fid="$( fixid "$file" )" - lfile="$( basename $file | sed "s|_input$|_label|g" )" - labelname="$( basename $file | sed "s|_input$||g" )" + lfile="$( basename "$file" | sed "s|_input$|_label|g" )" + labelname="$( basename "$file" | sed "s|_input$||g" )" - if [ ! "$path/$lfile" = "$file" -a -f "$path/$lfile" ] - then + if [ ! "$path/$lfile" = "$file" ] && [ -f "$path/$lfile" ] + then labelname="$( cat "$path/$lfile" )" fi echo "DIMENSION $fid '$labelname' $algorithm $multiplier $divisor" - echo >>$TMP_DIR/sensors.sh "echo \"SET $fid = \"\$(< $file )" + echo >>"$TMP_DIR/sensors.sh" "echo \"SET $fid = \"\$(< $file )" done - echo >>$TMP_DIR/sensors.sh "echo END" + echo >>"$TMP_DIR/sensors.sh" "echo END" done done - [ $sensors_source_update -eq 1 ] && echo >>$TMP_DIR/sensors.sh "}" + [ $sensors_source_update -eq 1 ] && echo >>"$TMP_DIR/sensors.sh" "}" # ok, load the function sensors_update() we created - [ $sensors_source_update -eq 1 ] && . $TMP_DIR/sensors.sh + # shellcheck source=/dev/null + [ $sensors_source_update -eq 1 ] && . "$TMP_DIR/sensors.sh" return 0 } @@ -244,7 +247,8 @@ sensors_update() { # for each dimension # remember: KEEP IT SIMPLE AND SHORT - [ $sensors_source_update -eq 0 ] && . $TMP_DIR/sensors.sh $1 + # shellcheck source=/dev/null + [ $sensors_source_update -eq 0 ] && . "$TMP_DIR/sensors.sh" "$1" return 0 } diff --git a/charts.d/squid.chart.sh b/charts.d/squid.chart.sh index 7a3a4f7941..aaa58fed08 100644 --- a/charts.d/squid.chart.sh +++ b/charts.d/squid.chart.sh @@ -1,4 +1,4 @@ -# shellcheck shell=bash +# shellcheck shell=bash disable=SC2154 # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0+ @@ -10,13 +10,12 @@ squid_host= squid_port= squid_url= -squid_timeout=2 squid_update_every=2 squid_priority=60000 squid_get_stats_internal() { local host="$1" port="$2" url="$3" - run squidclient -h $host -p $port $url + run squidclient -h "$host" -p "$port" "$url" } squid_get_stats() { @@ -32,7 +31,7 @@ squid_autodetect() { do x=$(squid_get_stats_internal "$host" "$port" "$url" | grep client_http.requests) if [ ! -z "$x" ] - then + then squid_host="$host" squid_port="$port" squid_url="$url" @@ -51,14 +50,16 @@ squid_check() { require_cmd sed || return 1 require_cmd egrep || return 1 - if [ -z "$squid_host" -o -z "$squid_port" -o -z "$squid_url" ] - then + if [ -z "$squid_host" ] || [ -z "$squid_port" ] || [ -z "$squid_url" ] + then squid_autodetect || return 1 fi # check once if the url works - local x="$(squid_get_stats | grep client_http.requests)" - if [ ! $? -eq 0 -o -z "$x" ] + local x + x="$(squid_get_stats | grep client_http.requests)" + # shellcheck disable=SC2181 + if [ ! $? -eq 0 ] || [ -z "$x" ] then error "cannot fetch URL '$squid_url' by connecting to $squid_host:$squid_port. Please set squid_url='url' and squid_host='host' and squid_port='port' in $confd/squid.conf" return 1 @@ -112,9 +113,10 @@ squid_update() { # prepare the script and always grep at the end the lines that are usefull, so that # even if something goes wrong, no other code can be executed + # shellcheck disable=SC1117 eval "$(squid_get_stats |\ sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/^\([a-z0-9_]\+\) *= *\([0-9]\+\)$/local squid_\1=\2/g" |\ - egrep "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$")" + grep -E "^local squid_(client_http|server_all)_[a-z0-9_]+=[0-9]+$")" # write the result of the work. cat <<VALUESEOF diff --git a/charts.d/tomcat.chart.sh b/charts.d/tomcat.chart.sh index aaa6332e00..18ec1f5ce0 100644 --- a/charts.d/tomcat.chart.sh +++ b/charts.d/tomcat.chart.sh @@ -47,6 +47,7 @@ tomcat_check() { fi if [ -z "${tomcat_user}" ]; then # check backwards compatibility + # shellcheck disable=SC2154 if [ -z "${tomcatUser}" ]; then error "tomcat user is unset or set to the empty string" return 1 @@ -56,6 +57,7 @@ tomcat_check() { fi if [ -z "${tomcat_password}" ]; then # check backwards compatibility + # shellcheck disable=SC2154 if [ -z "${tomcatPassword}" ]; then error "tomcat password is unset or set to the empty string" return 1 @@ -66,6 +68,7 @@ tomcat_check() { # check if we can get to tomcat's status page tomcat_get + # shellcheck disable=2181 if [ $? -ne 0 ] then error "cannot get to status page on URL '${tomcat_url}'. Please make sure tomcat url, username and password are correct." @@ -117,7 +120,6 @@ EOF # _update is called continuously, to collect the values tomcat_update() { - local reqs net # the first argument to this function is the microseconds since last update # pass this parameter to the BEGIN statement (see bellow). |