2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00

Fix shellcheck warnings in syncthing_

Signed-off-by: Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
This commit is contained in:
Pierre-Alain TORET 2018-03-24 19:16:03 +01:00
parent 5d5651ca09
commit f1afd73f71

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# -*- sh -*- # -*- sh -*-
: <<=cut : <<=cut
=head1 NAME =head1 NAME
@ -34,7 +34,7 @@ Pierre-Alain TORET <pierre-alain.toret@protonmail.com>
MIT MIT
=cut =cut
function cpu { cpu() {
case $1 in case $1 in
config) config)
cat <<'EOM' cat <<'EOM'
@ -46,12 +46,12 @@ syncthing_cpu.label cpu
EOM EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_cpu.value " CPU=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.cpuPercent')
$CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status | $JQ '.cpuPercent' printf "syncthing_cpu.value %s\\n" "$CPU"
esac esac
} }
function mem { mem() {
case $1 in case $1 in
config) config)
cat <<'EOM' cat <<'EOM'
@ -66,14 +66,16 @@ syncthing_mem_sys.label obtained
syncthing_mem_sys.cdef syncthing_mem_sys,8,* syncthing_mem_sys.cdef syncthing_mem_sys,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
ALL=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status | $JQ '.alloc') STATUS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status)
SYS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status | $JQ '.sys') ALL=$(echo "$STATUS" | $JQ '.alloc')
printf "syncthing_mem_all.value $ALL\nsyncthing_mem_sys.value $SYS\n" SYS=$(echo "$STATUS" | $JQ '.sys')
printf "syncthing_mem_all.value %s\\n" "$ALL"
printf "syncthing_mem_sys.value %s\\n" "$SYS"
esac esac
} }
function uptime { uptime() {
case $1 in case $1 in
config) config)
cat <<'EOM' cat <<'EOM'
@ -84,12 +86,12 @@ syncthing_uptime.label uptime
EOM EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_uptime.value " UPTIME=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.uptime')
$CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status | $JQ '.uptime' printf "syncthing_uptime.value %s\\n" "$UPTIME"
esac esac
} }
function goroutine { goroutine() {
case $1 in case $1 in
config) config)
cat <<'EOM' cat <<'EOM'
@ -100,12 +102,12 @@ syncthing_goroutine.label routines
EOM EOM
exit 0;; exit 0;;
*) *)
printf "syncthing_goroutine.value " GOROUTINES=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.goroutines')
$CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status | $JQ '.goroutines' printf "syncthing_goroutine.value %s\\n" "$GOROUTINES"
esac esac
} }
function transfer { transfer() {
case $1 in case $1 in
config) config)
cat <<'EOM' cat <<'EOM'
@ -124,32 +126,34 @@ syncthing_transfer_up.negative syncthing_transfer_down
syncthing_transfer_up.cdef syncthing_transfer_up,8,* syncthing_transfer_up.cdef syncthing_transfer_up,8,*
EOM EOM
exit 0;; exit 0;;
*) *)
IBT=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections | $JQ '.total | .inBytesTotal') CONNECTIONS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/connections)
OBT=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" $syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections | $JQ '.total | .outBytesTotal') IBT=$(echo "$CONNECTIONS" | $JQ '.total | .inBytesTotal')
printf "syncthing_transfer_up.value $IBT\nsyncthing_transfer_down.value $OBT\n" OBT=$(echo "$CONNECTIONS" | $JQ '.total | .outBytesTotal')
printf "syncthing_transfer_up.value %s\\n" "$IBT"
printf "syncthing_transfer_down.value %s\\n" "$OBT"
esac esac
} }
cd $(dirname $0) cd "$(dirname "$0")" || exit
CURL=$(which curl) CURL=$(which curl)
JQ=$(which jq) JQ=$(which jq)
case $(basename $0) in case $(basename "$0") in
syncthing_cpu) syncthing_cpu)
cpu $1 cpu "$1"
exit 0;; exit 0;;
syncthing_mem) syncthing_mem)
mem $1 mem "$1"
exit 0;; exit 0;;
syncthing_uptime) syncthing_uptime)
uptime $1 uptime "$1"
exit 0;; exit 0;;
syncthing_goroutine) syncthing_goroutine)
goroutine $1 goroutine "$1"
exit 0;; exit 0;;
syncthing_transfer) syncthing_transfer)
transfer $1 transfer "$1"
exit 0;; exit 0;;
esac esac