diff --git a/plugins/network/transmission_ratios/tr_ratios b/plugins/network/transmission_ratios/tr_ratios index 1e59ff3f..b2be2160 100755 --- a/plugins/network/transmission_ratios/tr_ratios +++ b/plugins/network/transmission_ratios/tr_ratios @@ -1,8 +1,6 @@ #!/bin/sh # -*- sh -*- -user='' -pass='' : <<=cut =head1 NAME @@ -39,29 +37,55 @@ unspecified =cut +CONNECTION_ARG="${host:-localhost}:${port:-9091}" +USERNAME="${username:-}" +PASSWORD="${password:-}" + + +# return a space separated list of transmissions with the following columns: +# * fieldname +# * ratio (in percent) +# * name of the transmissions +request_transmission_stats() { + if [ -n "$USERNAME$PASSWORD" ]; then + transmission-remote "$CONNECTION_ARG" --auth "$USERNAME:$PASSWORD" --list + else + transmission-remote "$CONNECTION_ARG" --list + fi | awk ' + BEGIN { FIELDWIDTHS = "7 4 13 10 7 9 7 13 40" } + NR > 1 { + split($1,torrentid," ") + # remove "*" from the ID of stopped transmissions + sub(/\*/, "", torrentid[1]) + if (torrentid[1] != "Sum:") { + split($7,ratio," ") + ratio[1] = ratio[1] * 100 + print "ID" torrentid[1], ratio[1], $9 + } + }' +} + + +if [ "$1" = "autoconf" ]; then + if [ -n "$(request_transmission_stats 2>/dev/null)" ]; then + echo "yes" + else + if which transmission-remote >/dev/null; then + echo "no (failed to connect to daemon)" + else + echo "no (missing 'transmission-remote' program)" + fi + fi + exit 0 +fi + if [ "$1" = "config" ]; then echo "graph_title Transmission seed ratios" echo "graph_vlabel Seed ratio %" echo "graph_category torrent" echo "graph_info This plugin shows your transmission ratios per torrent" - transmission-remote -n "$user:$pass" -l | awk ' - BEGIN { FIELDWIDTHS = "7 4 13 10 7 9 7 13 40" } - NR > 1 { - split($1,torrentid," ") - if (torrentid[1] != "Sum:") { - print "ID" torrentid[1] ".label " $9 - } - }' | iconv -f utf-8 -t ascii//translit + request_transmission_stats | awk '{print $1 ".label " $3 }' | iconv -f utf-8 -t ascii//translit exit 0 fi -transmission-remote -n "$user:$pass" -l | awk ' - BEGIN { FIELDWIDTHS = "7 4 13 10 7 9 7 13 40" } - NR > 1 { - split($1,torrentid," ") - if (torrentid[1] != "Sum:") { - split($7,ratio," ") - ratio[1] = ratio[1] * 100 - print "ID" torrentid[1] ".value " ratio[1] - } - }' +request_transmission_stats | awk '{print $1 ".value " $2 }'