1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

mpdstats_: allow to pass options to nc(1).

Different nc(1) implementations will use different flags, as highlighted
in #576. This environment variable allows one to pass any option to the
nc binary.
This commit is contained in:
ToM 2021-01-16 12:47:43 +01:00 committed by Lars Kruse
parent 829bab4814
commit 9ad3b1ff18

View file

@ -33,12 +33,19 @@ please use the environment variables 'mpd_host' and 'mpd_port' to connect.
Also, if your netcat(1) binary is anywhere else than /bin/nc please define Also, if your netcat(1) binary is anywhere else than /bin/nc please define
it using the 'netcat' environment variable. it using the 'netcat' environment variable.
Different netcat implementations use different flags. In the MPD command
protocol, it is up to the client to close the connection, so you want to use
a timeout flag. For instance, Fedora/Debian will use ncat, which uses '-w'
as a timeout option.
You can configure this using the 'netcat_args' environment variable.
=head2 CONFIGURATION EXAMPLE =head2 CONFIGURATION EXAMPLE
[mpdstats_*] [mpdstats_*]
env.mpd_host 192.168.0.43 env.mpd_host 192.168.0.43
env.mpd_port 6606 env.mpd_port 6606
env.netcat /usr/local/bin/nc env.netcat /usr/local/bin/nc
env.netcat_args -w 2
=head1 AUTHOR =head1 AUTHOR
@ -73,6 +80,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
MPDHOST=${mpd_host:-localhost} MPDHOST=${mpd_host:-localhost}
MPDPORT=${mpd_port:-6600} MPDPORT=${mpd_port:-6600}
NCBIN=${netcat:-$(which nc)} NCBIN=${netcat:-$(which nc)}
NCARGS=${netcat_args:-""}
ACTION="$(basename "$0" | sed 's/^.*_//')" ACTION="$(basename "$0" | sed 's/^.*_//')"
@ -83,7 +91,7 @@ ACTION="$(basename "$0" | sed 's/^.*_//')"
do_autoconf () { do_autoconf () {
if [ -z "$NCBIN" ] ; then if [ -z "$NCBIN" ] ; then
echo "no (missing netcat program ('nc'))" echo "no (missing netcat program ('nc'))"
elif ! echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" >/dev/null 2>&1; then elif ! echo stats | "$NCBIN" "$NCARGS" "$MPDHOST" "$MPDPORT" >/dev/null 2>&1; then
echo "no (connection failed)" echo "no (connection failed)"
else else
echo "yes" echo "yes"
@ -93,7 +101,7 @@ do_autoconf () {
get_mpd_stats_keys() { get_mpd_stats_keys() {
echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk 'BEGIN {FS=":"} /^[^ ]+:/ {print $1}' echo stats | "$NCBIN" "$NCARGS" "$MPDHOST" "$MPDPORT" | awk 'BEGIN {FS=":"} /^[^ ]+:/ {print $1}'
} }
@ -102,7 +110,7 @@ print_mpd_stat_value() {
local fieldname local fieldname
local stat_value local stat_value
fieldname="$(clean_fieldname "$key")" fieldname="$(clean_fieldname "$key")"
stat_value="$(echo stats | "$NCBIN" "$MPDHOST" "$MPDPORT" | awk "/^${key}:/ {print \$2}")" stat_value="$(echo stats | "$NCBIN" "$NCARGS" "$MPDHOST" "$MPDPORT" | awk "/^${key}:/ {print \$2}")"
echo "${fieldname}.value $stat_value" echo "${fieldname}.value $stat_value"
} }