Skip to content
Permalink
Browse files

Fix multiple shellcheck issues

  • Loading branch information...
sumpfralle committed Aug 13, 2019
1 parent 5b1099f commit 7fed3b9765978940ac17359b059a5f6e737e91fb
@@ -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
@@ -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
@@ -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"
@@ -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))
@@ -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; }')
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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

@@ -96,4 +96,4 @@ else
connections=U
fi

printf "connections.value %s\n" "$connections"
printf 'connections.value %s\n' "$connections"
@@ -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')"
@@ -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

@@ -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"
@@ -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
}

@@ -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
}

@@ -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

0 comments on commit 7fed3b9

Please sign in to comment.
You can’t perform that action at this time.