PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/node.d/squeezebox_.in

https://bitbucket.org/schatt/munin
Autoconf | 213 lines | 169 code | 32 blank | 12 comment | 22 complexity | d2aecdde2a8e536565bc8fdcafe0c5e1 MD5 | raw file
  1. #!@@BASH@@
  2. # -*- sh -*-
  3. : <<=cut
  4. =head1 NAME
  5. squeezebox_ - plugin to monitor a SqueezeCenter and associated
  6. players.
  7. =head1 APPLICABLE SYSTEMS
  8. Probably any system running SqueezeCenter. Change the host to allow
  9. for remote monitoring.
  10. =head1 CONFIGURATION
  11. No configuration should be required if run on the same server as
  12. SqueezeCenter. If the plugin is run from another unit or in a
  13. non-default configuration, please use the environment variables
  14. 'squeezebox_host' and 'squeezebox_port' to connect. Also, if your
  15. nc(1) binary is not called "nc", or not the one in $PATH, please define it
  16. in the plugin's environment file (@@CONFDIR@@/squeezebox or similar).
  17. Sample follows:
  18. [squeezebox_*]
  19. env.squeezebox_host 192.168.100.10
  20. env.squeezebox_port 9095
  21. env.netcat /usr/local/bin/nc
  22. =head1 INTERPRETATION
  23. The "volume" graphs only graphs the player's volume, not the amplifier
  24. or whatever the player is connected to.
  25. =head1 MAGIC MARKERS
  26. #%# family=auto
  27. #%# capabilities=autoconf suggest
  28. =head1 VERSION
  29. $Id$
  30. =head1 BUGS
  31. None known
  32. =head1 AUTHOR
  33. Bjørn Ruberg
  34. =head1 LICENSE
  35. GPLv2
  36. =cut
  37. HOST=${squeezecenter_host:-localhost}
  38. PORT=${squeezecenter_port:-9090}
  39. NC=${netcat:-nc}
  40. if [ "$1" = "autoconf" ]; then
  41. if [ ! "which $NC 1>/dev/null 2>&1" ]; then
  42. echo "no (no netcat/nc binary found)"
  43. exit 0
  44. fi
  45. echo exit | $NC $HOST $PORT 1>/dev/null 2>&1
  46. RET=$?
  47. if [ "$RET" != "0" ]; then
  48. echo "no (no connection on $HOST port $PORT)"
  49. exit 0
  50. fi
  51. VERSION=$(printf "%b" "version ?\nexit\n" | $NC $HOST $PORT 2>/dev/null)
  52. if [ "$VERSION" != "" ]; then
  53. echo "yes"
  54. exit 0
  55. else
  56. echo "no (socket responding but version not found: something is weird)"
  57. exit 0
  58. fi
  59. fi
  60. if [ "$1" = "suggest" ]; then
  61. echo "songs"
  62. echo "artists"
  63. echo "albums"
  64. echo "genres"
  65. echo "years"
  66. echo "signalstrength"
  67. echo "volume"
  68. exit 0
  69. fi
  70. # Add this plugin to a cron job with the argument "update"
  71. # Adjust the interval to your own tempo for adding/deleting
  72. # music :-)
  73. #
  74. # example: 5 * * * * /usr/share/munin/plugins/squeezebox_ update
  75. if [ "$1" = "update" ]; then
  76. printf "%b" "rescan\nexit\n" | $NC $HOST $PORT >/dev/null
  77. exit 0
  78. fi
  79. CHECK=$(echo $0 | cut -d _ -f 2-)
  80. case "$CHECK" in
  81. songs)
  82. ATTR="songs"
  83. ;;
  84. artists)
  85. ATTR="artists"
  86. ;;
  87. albums)
  88. ATTR="albums"
  89. ;;
  90. genres)
  91. ATTR="genres"
  92. ;;
  93. years)
  94. CMD="years"
  95. ;;
  96. signalstrength)
  97. CMD="signalstrength"
  98. TITLE="Signal strength"
  99. ;;
  100. volume)
  101. CMD="mixer volume"
  102. TITLE="Mixer volume"
  103. ;;
  104. *)
  105. echo "Can't run without a proper symlink. Exiting."
  106. echo "Try running munin-node-configure --suggest."
  107. exit 1
  108. ;;
  109. esac
  110. if [ "$ATTR" = "" -a "$CMD" = "" ]; then
  111. echo "Urk"
  112. exit 2
  113. fi
  114. if [ "$CMD" = "years" ]; then
  115. no_of_years=$(printf "%b" "years\nexit\n" | $NC $HOST $PORT | sed 's/%3A/:/g' | cut -d ':' -f 2)
  116. years_array=$(printf "%b" "years 0 $no_of_years\nexit\n" | $NC $HOST $PORT | sed 's/%3A/:/g' | cut -d ' ' -f 4- | sed 's/year://g' | cut -d ' ' -f -$no_of_years)
  117. arr1=( `echo "$years_array" | tr -s ' ' ' '` )
  118. (( no_of_years-- )) # We don't need that last entry in the array
  119. if [ "$1" = "config" ]; then
  120. echo "graph_title Number of years"
  121. echo "graph_category Squeezebox"
  122. echo "graph_args --base 1000 -l 0"
  123. # echo -n "graph_order "
  124. # echo $years_array | tr '[:space:]' " y"
  125. # echo "graph_order y0"
  126. printf "graph_order y"
  127. echo $years_array | sed 's/ / y/g'
  128. for i in `seq 0 $no_of_years`; do
  129. year=$(echo ${arr1[$i]})
  130. if [ $year = 0 ]; then
  131. echo y0.label No year
  132. else
  133. echo y${year}.label $year
  134. fi
  135. if [ $i = 0 ]; then
  136. echo y${year}.draw AREA
  137. else
  138. echo y${year}.draw STACK
  139. fi
  140. done
  141. exit 0
  142. fi
  143. for i in `seq 0 $no_of_years`; do
  144. year=$(echo ${arr1[$i]})
  145. printf "y%s.value " ${year}
  146. printf "%b" "albums 0 0 year:${year}\nexit\n" | $NC $HOST $PORT | sed 's/%3A/:/g' | cut -d ':' -f 3
  147. done
  148. elif [ "$CMD" = "signalstrength" -o "$CMD" = "mixer volume" ]; then
  149. if [ "$1" = "config" ]; then
  150. echo "graph_title $TITLE"
  151. echo "graph_category Squeezebox"
  152. COUNT=$(printf "%b" "player count ?\nexit\n" | $NC $HOST $PORT | cut -d " " -f 3)
  153. (( COUNT-- ))
  154. for ID in $(seq 0 $COUNT); do
  155. MAC=$(printf "%b" "player id $ID ?\nexit\n" | $NC $HOST $PORT | cut -d " " -f 4 | sed 's/%3A/:/g')
  156. NAME=$(printf "%b" "player name $MAC ?\nexit\n" | $NC $HOST $PORT | cut -d " " -f 4 | sed 's/%20/ /g')
  157. MAC2=$(echo $MAC | sed 's/://g; s/\./_/g')
  158. echo "$MAC2.label $NAME"
  159. done
  160. exit 0
  161. fi
  162. COUNT=$(printf "%b" "player count ?\nexit\n" | $NC $HOST $PORT | cut -d " " -f 3)
  163. (( COUNT-- ))
  164. for ID in $(seq 0 $COUNT); do
  165. MAC=$(printf "%b" "player id $ID ?\nexit\n" | $NC $HOST $PORT | cut -d " " -f 4 | sed 's/%3A/:/g')
  166. VAL=$(printf "%b" "$MAC $CMD ?\nexit\n"| $NC $HOST $PORT | cut -d " " -f 2- | sed "s/$CMD //")
  167. MAC2=$(echo $MAC| sed 's/://g')
  168. echo "$MAC2.value $VAL"
  169. done
  170. else
  171. if [ "$1" = "config" ]; then
  172. echo "graph_title Number of $ATTR"
  173. echo "graph_scale no"
  174. echo "graph_category Squeezebox"
  175. echo "$ATTR.label $ATTR"
  176. exit 0
  177. fi
  178. CMD="info total $ATTR "
  179. echo -n "$ATTR.value "
  180. printf "%b" "$CMD ?\nexit\n" | $NC $HOST $PORT | sed "s/^$CMD//"
  181. fi