diff --git a/plugins/debian/deborphan b/plugins/debian/deborphan index 10d5ac44..633ac7df 100755 --- a/plugins/debian/deborphan +++ b/plugins/debian/deborphan @@ -76,7 +76,7 @@ EOF else for CAT in ${CATEGORIES}; do CATFIELD=$(clean_fieldname "${CAT}") - CATDATA=$(echo "${OUT}" | sed -n "s#${CAT} \+##p") + CATDATA=$(echo "${OUT}" | sed -n 's#'"${CAT}"' \+##p') echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)" echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')" done diff --git a/plugins/debian/debsecan_ b/plugins/debian/debsecan_ index c78a797d..7ef84e1d 100755 --- a/plugins/debian/debsecan_ +++ b/plugins/debian/debsecan_ @@ -169,7 +169,7 @@ case "${MODE}" in esac # Reformat the output of the cut|sort|uniq... to a more human-friendly "item (count)" format -CVECOUNTRE="s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/" +CVECOUNTRE='s/^ *\([0-9]\+\) \+\([^ ]\+\)/\2 (\1)/' # shellcheck disable=SC2005 disable=SC2046 # The nested $(echo ...)s are needed to yet the newlines diff --git a/plugins/ejabberd/ejabberd_stats_ b/plugins/ejabberd/ejabberd_stats_ index 9eb7c184..42200fad 100755 --- a/plugins/ejabberd/ejabberd_stats_ +++ b/plugins/ejabberd/ejabberd_stats_ @@ -22,7 +22,7 @@ #%# capabilities=autoconf suggest EJABBERDCTL=${ejabberdctl:-$(which ejabberdctl)} -SCRIPT_NAME=$(basename $0) +SCRIPT_NAME=$(basename "$0") STATS_TYPE="${SCRIPT_NAME/ejabberd_stats_/}" function ejabberd_stats_connected_users() { @@ -81,4 +81,4 @@ SUGGESTIONS ;; esac -ejabberd_stats_${STATS_TYPE} $1 +"ejabberd_stats_${STATS_TYPE}" "$1" diff --git a/plugins/ilias/ilias_session b/plugins/ilias/ilias_session index 5f85a7c4..ad227ebf 100755 --- a/plugins/ilias/ilias_session +++ b/plugins/ilias/ilias_session @@ -154,6 +154,7 @@ config() { # -v varname # True if the shell variable varname is set (has been assigned a value). # https://stackoverflow.com/a/45385463/2683737 + # shellcheck disable=SC2102 while [[ -v d_attr[$i,field] ]]; do field=${d_attr[$i,field]} echo "$field.type ${d_attr[$i,type]}" @@ -181,6 +182,7 @@ fetch() { # create an array of queries i=0 + # shellcheck disable=SC2102 while [[ -v d_attr[$i,field] ]]; do query+=("${d_attr[$i,sql]}") ((++i)) @@ -211,6 +213,7 @@ fetch() { # extract result and echo it to stdout, which is # captured by Munin i=0 + # shellcheck disable=SC2102 while [[ -v d_attr[$i,field] ]]; do echo "${d_attr[$i,field]}.value ${results[$i]}" ((++i)) diff --git a/plugins/minecraft/minecraft-users-ram_ b/plugins/minecraft/minecraft-users-ram_ index 0520935d..1de3aaa7 100755 --- a/plugins/minecraft/minecraft-users-ram_ +++ b/plugins/minecraft/minecraft-users-ram_ @@ -49,7 +49,7 @@ fi PLAYERCOUNT=$(LC_LANG=C netstat -tn | grep ":$MC_PORT " | grep ESTABLISHED | wc -l) MC_PID=$(netstat -tlpn | grep ":$MC_PORT " | sed -n -e '1p' | awk '{ print $7 }' | cut -d '/' -f1) -if [ ! -z "${MC_PID}" ] +if [ -n "${MC_PID}" ] then #is running MEMGiB=$(ps -p "$MC_PID" -o rss | sed -n '2p' | awk '{ print $1 / 1024 / 1024 }') CPU=$(top -bp "$MC_PID" -n 1 | sed -n '$p' | awk '{ print $10 / 100; }') diff --git a/plugins/munin/munin_events b/plugins/munin/munin_events index 2a355bd9..73f36dd0 100755 --- a/plugins/munin/munin_events +++ b/plugins/munin/munin_events @@ -71,7 +71,7 @@ do_value() { FIELD="$1" EVENT_LABEL="$2" - EVENT_COUNT="$("$logtail_bin" -t "$muninupdate" 2> /dev/null | grep -c "^[0-9/: ]\{19\} \[${EVENT_LABEL}\]")" + EVENT_COUNT="$("$logtail_bin" -t "$muninupdate" 2> /dev/null | grep -c '^[0-9/: ]\{19\} \['"${EVENT_LABEL}"'\]')" if echo "$EVENT_COUNT" | grep -q "[^0-9]"; then echo "Cannot determine event count" 1>&2 exit 10 diff --git a/plugins/nfs-freebsd/nfs_client b/plugins/nfs-freebsd/nfs_client index 312fb6f2..ef930f4e 100755 --- a/plugins/nfs-freebsd/nfs_client +++ b/plugins/nfs-freebsd/nfs_client @@ -37,16 +37,16 @@ if [ "$1" = "autoconf" ]; then fi fi -labels=`$NFSSTAT -c | grep -iv "[0-9]" | grep -v ":" | sed 's/X\ /x_/' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}' | tr '[A-Z]' '[a-z]'` -values=`$NFSSTAT -c | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}'` +labels=$("$NFSSTAT" -c | grep -iv "[0-9]" | grep -v ":" | sed 's/X\ /x_/' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}' | tr '[:upper:]' '[:lower:]') +values=$("$NFSSTAT" -c | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26}') -larray=( $labels ) -varray=( $values ) +read -r -a larray <<<"$labels" +read -r -a varray <<<"$values" if [ "$1" = "config" ]; then echo 'graph_title NFSv3 Client' echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel requests / ${graph_period}' + echo "graph_vlabel requests / \${graph_period}" echo 'graph_total total' echo 'graph_category fs' for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done diff --git a/plugins/nfs-freebsd/nfs_client_cache b/plugins/nfs-freebsd/nfs_client_cache index 9c5d3441..3be86392 100755 --- a/plugins/nfs-freebsd/nfs_client_cache +++ b/plugins/nfs-freebsd/nfs_client_cache @@ -37,16 +37,16 @@ if [ "$1" = "autoconf" ]; then fi fi -labels=`$NFSSTAT -c | grep -iv "[0-9]" | tail -n 2 | sed 's/BioRLHits/BioRL\ Hits/g' | awk '{print $1"_"$2,$1"_"$3,$4"_"$5,$4"_"$6,$7"_"$8,$7"_"$9,$10"_"$11,$10"_"$12}' | tr '\n' ' ' | tr '[A-Z]' '[a-z]'` -values=`$NFSSTAT -c | grep -i "[0-9]" | tail -n 2 | tr '\n' ' '` +labels=$("$NFSSTAT" -c | grep -iv "[0-9]" | tail -n 2 | sed 's/BioRLHits/BioRL\ Hits/g' | awk '{print $1"_"$2,$1"_"$3,$4"_"$5,$4"_"$6,$7"_"$8,$7"_"$9,$10"_"$11,$10"_"$12}' | tr '\n' ' ' | tr '[:upper:]' '[:lower:]') +values=$("$NFSSTAT" -c | grep -i "[0-9]" | tail -n 2 | tr '\n' ' ') -larray=( $labels ) -varray=( $values ) +read -r -a larray <<<"$labels" +read -r -a varray <<<"$values" if [ "$1" = "config" ]; then echo 'graph_title NFSv3 Client Cache' echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel requests / ${graph_period}' + echo "graph_vlabel requests / \${graph_period}" echo 'graph_total total' echo 'graph_category fs' for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done diff --git a/plugins/nfs-freebsd/nfsd b/plugins/nfs-freebsd/nfsd index d551b844..d2e3d848 100755 --- a/plugins/nfs-freebsd/nfsd +++ b/plugins/nfs-freebsd/nfsd @@ -38,17 +38,17 @@ if [ "$1" = "autoconf" ]; then fi fi -labels=`$NFSSTAT -s | grep -iv "[0-9]" | grep -v ":" | sed 's/Server\ //' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}' | tr '[A-Z]' '[a-z]'` -values=`$NFSSTAT -s | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}'` +labels=$("$NFSSTAT" -s | grep -iv "[0-9]" | grep -v ":" | sed 's/Server\ //' | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}' | tr '[:upper:]' '[:lower:]') +values=$("$NFSSTAT" -s | grep -i "[0-9]" | tr '\n' ' ' | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30}') -larray=( $labels ) -varray=( $values ) +read -r -a larray <<<"$labels" +read -r -a varray <<<"$values" if [ "$1" = "config" ]; then echo 'graph_title NFSv3 Server' echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel requests / ${graph_period}' + echo "graph_vlabel requests / \${graph_period}" echo 'graph_total total' echo 'graph_category fs' for a in $labels; do echo "$a.label $a" ; echo "$a.type DERIVE"; echo "$a.min 0"; done diff --git a/plugins/nscd/nscd_ b/plugins/nscd/nscd_ index b8919a55..00bde9f8 100755 --- a/plugins/nscd/nscd_ +++ b/plugins/nscd/nscd_ @@ -33,19 +33,23 @@ #%# family=auto #%# capabilities=autoconf suggest -source $MUNIN_LIBDIR/plugins/plugin.sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" NSCD_CFG=${nscd_cfg:-/etc/nscd.conf} AUTOCONF_CHECK=$(nscd -g | grep -ic 'yes.*cache is enabled') -SUGGEST_CHECK=$(nscd -g | grep -iB2 'yes.*cache is enabled' | awk {'print $1'} | head -1) -MODE=$(basename $0 | sed 's/^nscd_//g' | tr '_' '.') +SUGGEST_CHECK=$(nscd -g | grep -iB2 'yes.*cache is enabled' | awk '{print $1}' | head -1) +MODE=$(basename "$0" | sed 's/^nscd_//g' | tr '_' '.') case $1 in autoconf) - [ -r "$NSCD_CFG" ] && [ $AUTOCONF_CHECK -gt 0 ] && echo yes || echo "no (nscd config not found or no database enabled)" + if [ -r "$NSCD_CFG" ] && [ "$AUTOCONF_CHECK" -gt 0 ]; then + echo yes + else + echo "no (nscd config not found or no database enabled)" + fi exit 0 ;; suggest) - echo $SUGGEST_CHECK + echo "$SUGGEST_CHECK" exit 0 ;; config) @@ -66,7 +70,7 @@ CONFIG ;; fetch|*) nscd -g | awk "/^$MODE cache/ {printline = 1; print; next} /^.*cache:/ {printline = 0} printline" | \ - egrep '(suggested size|cache hit rate|current number of cached values|maximum number of cached values)' | \ - sed 's/%//' | awk {' if (NR==1) print "suggestedsize.value " $1; if (NR==2) print "cachehitrate.value " $1; if (NR==3) print "currnumber.value " $1; if (NR==4) print "maxnumber.value " $1'} + grep -E '(suggested size|cache hit rate|current number of cached values|maximum number of cached values)' | \ + sed 's/%//' | awk '{ if (NR==1) print "suggestedsize.value " $1; if (NR==2) print "cachehitrate.value " $1; if (NR==3) print "currnumber.value " $1; if (NR==4) print "maxnumber.value " $1}' ;; esac diff --git a/plugins/quake/qstatcod4and5_ b/plugins/quake/qstatcod4and5_ index cf027e34..f1fd36d1 100755 --- a/plugins/quake/qstatcod4and5_ +++ b/plugins/quake/qstatcod4and5_ @@ -64,7 +64,7 @@ quake_stat() { port=$3 fi - if [ ! -z "$gametype" ] && [ ! -z "$gametype" ] && [ ! -z "$gametype" ]; then + if [ -n "$gametype" ] && [ -n "$gametype" ] && [ -n "$gametype" ]; then dummy=$("$qstat_exe" -P -pa -sort P "-$gametype" "${ip}:${port}" | grep frags | wc -l) playervalue=$dummy diff --git a/plugins/rabbitmq/rabbitmq_connections b/plugins/rabbitmq/rabbitmq_connections index fd755968..73f770ec 100755 --- a/plugins/rabbitmq/rabbitmq_connections +++ b/plugins/rabbitmq/rabbitmq_connections @@ -96,4 +96,4 @@ else connections=U fi -printf "connections.value %s\n" "$connections" +printf 'connections.value %s\n' "$connections" diff --git a/plugins/raspberry-pi/raspi_temp b/plugins/raspberry-pi/raspi_temp index 55f85e45..5918b4e8 100755 --- a/plugins/raspberry-pi/raspi_temp +++ b/plugins/raspberry-pi/raspi_temp @@ -48,4 +48,4 @@ EOM exit 0;; esac -echo "temp.value $(vcgencmd measure_temp | sed -n "s/temp=\(.*\)\'C/\1/p")" +echo "temp.value $(vcgencmd measure_temp | sed -n 's/temp=\(.*\)'"'"'C/\1/p')" diff --git a/plugins/ssl/ssl-certificate-expiry b/plugins/ssl/ssl-certificate-expiry index f338a8f5..d2d56f30 100755 --- a/plugins/ssl/ssl-certificate-expiry +++ b/plugins/ssl/ssl-certificate-expiry @@ -70,7 +70,7 @@ HOSTPORT=${0##*ssl-certificate-expiry_} CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").cache" if [ "${HOSTPORT}" != "${0}" ] \ - && [ ! -z "${HOSTPORT}" ]; then + && [ -n "${HOSTPORT}" ]; then services="${HOSTPORT}" fi diff --git a/plugins/ssl/ssl_ b/plugins/ssl/ssl_ index 496453f1..5c1c4fcc 100755 --- a/plugins/ssl/ssl_ +++ b/plugins/ssl/ssl_ @@ -84,4 +84,4 @@ cert=$(echo "" | openssl s_client -CApath /etc/ssl/certs -servername "${SITE}" - days_left=$(echo "$cert" | parse_valid_days_from_certificate) [ -n "$days_left" ] || days_left="U" -printf "expire.value %s\n" "$days_left" +printf 'expire.value %s\n' "$days_left" diff --git a/plugins/syncthing/strelaysrv_ b/plugins/syncthing/strelaysrv_ index dabc504e..a5a31927 100755 --- a/plugins/syncthing/strelaysrv_ +++ b/plugins/syncthing/strelaysrv_ @@ -57,10 +57,10 @@ EOM NC=$(echo "$STATUS" | $JQ '.numConnections ') NK=$(echo "$STATUS" | $JQ '.numPendingSessionKeys ') NP=$(echo "$STATUS" | $JQ '.numProxies ') - printf "strelaysrv_num_sessions.value %s\n" "$NS" - printf "strelaysrv_num_connections.value %s\n" "$NC" - printf "strelaysrv_num_pending.value %s\n" "$NK" - printf "strelaysrv_num_proxies.value %s\n" "$NP" + printf 'strelaysrv_num_sessions.value %s\n' "$NS" + printf 'strelaysrv_num_connections.value %s\n' "$NC" + printf 'strelaysrv_num_pending.value %s\n' "$NK" + printf 'strelaysrv_num_proxies.value %s\n' "$NP" esac } @@ -77,7 +77,7 @@ EOM *) STATUS=$(getstatus) UPTIME=$(echo "$STATUS" | "$JQ" '.uptimeSeconds') - printf "strelaysrv_uptime.value %s\n" "$UPTIME" + printf 'strelaysrv_uptime.value %s\n' "$UPTIME" esac } @@ -94,7 +94,7 @@ EOM *) STATUS=$(getstatus) GOROUTINE=$(echo "$STATUS" | "$JQ" '.goNumRoutine') - printf "strelaysrv_goroutine.value %s\n" "$GOROUTINE" + printf 'strelaysrv_goroutine.value %s\n' "$GOROUTINE" esac } @@ -113,7 +113,7 @@ EOM *) STATUS=$(getstatus) BP=$(echo "$STATUS" | "$JQ" '.bytesProxied ') - printf "strelaysrv_proxied.value %s\n" "$BP" + printf 'strelaysrv_proxied.value %s\n' "$BP" esac } @@ -132,7 +132,7 @@ EOM *) STATUS=$(getstatus) TRANSFER=$(echo "$STATUS" | "$JQ" '.kbps10s1m5m15m30m60m[2] ') - printf "strelaysrv_transfer.value %s\n" "$TRANSFER" + printf 'strelaysrv_transfer.value %s\n' "$TRANSFER" esac } diff --git a/plugins/syncthing/syncthing_ b/plugins/syncthing/syncthing_ index 8c7fc8a9..05efc7dd 100755 --- a/plugins/syncthing/syncthing_ +++ b/plugins/syncthing/syncthing_ @@ -57,7 +57,7 @@ EOM *) STATUS=$(getstatus) CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent') - printf "syncthing_cpu.value %s\n" "$CPU" + printf 'syncthing_cpu.value %s\n' "$CPU" esac } @@ -80,8 +80,8 @@ EOM STATUS=$(getstatus) ALL=$(echo "$STATUS" | "$JQ" '.alloc') SYS=$(echo "$STATUS" | "$JQ" '.sys') - printf "syncthing_mem_all.value %s\n" "$ALL" - printf "syncthing_mem_sys.value %s\n" "$SYS" + printf 'syncthing_mem_all.value %s\n' "$ALL" + printf 'syncthing_mem_sys.value %s\n' "$SYS" esac } @@ -98,7 +98,7 @@ EOM *) STATUS=$(getstatus) UPTIME=$(echo "$STATUS" | "$JQ" '.uptime') - printf "syncthing_uptime.value %s\n" "$UPTIME" + printf 'syncthing_uptime.value %s\n' "$UPTIME" esac } @@ -115,7 +115,7 @@ EOM *) STATUS=$(getstatus) GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines') - printf "syncthing_goroutine.value %s\n" "$GOROUTINES" + printf 'syncthing_goroutine.value %s\n' "$GOROUTINES" esac } @@ -142,8 +142,8 @@ EOM CONNECTIONS=$("$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections") IBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .inBytesTotal') OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal') - printf "syncthing_transfer_up.value %s\n" "$IBT" - printf "syncthing_transfer_down.value %s\n" "$OBT" + printf 'syncthing_transfer_up.value %s\n' "$IBT" + printf 'syncthing_transfer_down.value %s\n' "$OBT" esac } diff --git a/plugins/zfs/zfs-filesystem-graph b/plugins/zfs/zfs-filesystem-graph index 1324f95d..8bc3ca07 100755 --- a/plugins/zfs/zfs-filesystem-graph +++ b/plugins/zfs/zfs-filesystem-graph @@ -21,7 +21,7 @@ # For now this plugin does not allow "_" in the name of a zpool or filesystems # -myname=`basename $0 | sed 's/^zfs_fs_//g' | sed -e 's/_/\//g'` +myname=$(basename "$0" | sed 's/^zfs_fs_//g' | sed -e 's/_/\//g') if [ "$1" = "autoconf" ]; then # Makes little sense to autoconf if you can't suggest @@ -33,7 +33,9 @@ if [ "$1" = "suggest" ]; then exit 0 fi -values=( $(zfs get -p usedbydataset,usedbychildren,usedbysnapshots,usedbyrefreservation,available,quota $myname | awk 'BEGIN {total=0;} { if( NR==1 ) next; } !/quota/ {total=total+$3;} {print $3} END{print total;}') ) +read -r -a values <<<"$(zfs get -p usedbydataset,usedbychildren,usedbysnapshots,usedbyrefreservation,available,quota "$myname" \ + | awk 'BEGIN {total=0;} { if( NR==1 ) next; } !/quota/ {total=total+$3;} {print $3} END{print total;}')" + if [ "$1" = "config" ]; then