From 8be793e8224a5495bc02a7d04b1ecdef4266a905 Mon Sep 17 00:00:00 2001 From: Matt West Date: Thu, 9 Feb 2012 15:05:03 -0800 Subject: [PATCH] Fixing shoutcast2_multi plugin --- plugins/other/shoutcast2_multi | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/other/shoutcast2_multi b/plugins/other/shoutcast2_multi index e1202ad8..e862fffc 100755 --- a/plugins/other/shoutcast2_multi +++ b/plugins/other/shoutcast2_multi @@ -32,6 +32,7 @@ use strict; use warnings; use LWP::UserAgent; use XML::Simple; +use Data::Dumper; use Munin::Plugin; need_multigraph(); @@ -146,12 +147,22 @@ sub main { } my $streamConfigRef = $adminRef->{STREAMCONFIGS}->{STREAMCONFIG}; my $sidDataRef; - foreach my $sid (keys %{$streamConfigRef}) { + if ($adminRef->{STREAMCONFIGS}->{TOTALCONFIGS} == 1) { + my $sid = $streamConfigRef->{id}; my ($return,$tmpSidRef) = fetch_sid_data($sid); if ($return == 0) { - next; + # Only one stream, and we didn't get a good response. + exit; } $sidDataRef->{$sid} = $tmpSidRef; + } else { + foreach my $sid (keys %{$streamConfigRef}) { + my ($return,$tmpSidRef) = fetch_sid_data($sid); + if ($return == 0) { + next; + } + $sidDataRef->{$sid} = $tmpSidRef; + } } print_active_data($sidDataRef); print_listener_data($adminRef->{STREAMCONFIGS}->{SERVERMAXLISTENERS}, $sidDataRef); @@ -209,12 +220,22 @@ sub config { } my $streamConfigRef = $adminRef->{STREAMCONFIGS}->{STREAMCONFIG}; my $sidDataRef; - foreach my $sid (keys %{$streamConfigRef}) { + if ($adminRef->{STREAMCONFIGS}->{TOTALCONFIGS} == 1) { + my $sid = $streamConfigRef->{id}; my ($return,$tmpSidRef) = fetch_sid_data($sid); if ($return == 0) { - next; + # Only one stream, and we didn't get a good response. + exit; } $sidDataRef->{$sid} = $tmpSidRef; + } else { + foreach my $sid (keys %{$streamConfigRef}) { + my ($return,$tmpSidRef) = fetch_sid_data($sid); + if ($return == 0) { + next; + } + $sidDataRef->{$sid} = $tmpSidRef; + } } print_active_config($sidDataRef); print_listener_config($sidDataRef); @@ -244,7 +265,7 @@ sub print_active_config { print "graph_title ".$graphsRef->{active}->{config}->{title}."\n"; print "graph_args ".$graphsRef->{active}->{config}->{args}."\n"; print "graph_vlabel ".$graphsRef->{active}->{config}->{vlabel}."\n"; - print "graph_category".$graphsRef->{active}->{config}->{category}."\n"; + print "graph_category ".$graphsRef->{active}->{config}->{category}."\n"; print "graph_info ".$graphsRef->{active}->{config}->{info}."\n"; # Print the Data Value Info foreach my $dsrc (@{$graphsRef->{active}->{datasrc}}) { @@ -279,7 +300,7 @@ sub print_listener_config { print "graph_title ".$graphsRef->{listeners}->{config}->{title}."\n"; print "graph_args ".$graphsRef->{listeners}->{config}->{args}."\n"; print "graph_vlabel ".$graphsRef->{listeners}->{config}->{vlabel}."\n"; - print "graph_category".$graphsRef->{listeners}->{config}->{category}."\n"; + print "graph_category ".$graphsRef->{listeners}->{config}->{category}."\n"; print "graph_info ".$graphsRef->{listeners}->{config}->{info}."\n"; # Print the Data Value Info foreach my $dsrc (@{$graphsRef->{listeners}->{datasrc}}) {