Révision a2dd3b1b
Adding shoutcast2_multi plugin written in perl, should function on both 32bit and 64bit machines
| plugins/other/shoutcast2_multi | ||
|---|---|---|
| 1 |
#!/usr/bin/perl |
|
| 2 |
# |
|
| 3 |
=head1 Shoutcast 2.0.x Plugin |
|
| 4 |
|
|
| 5 |
A Plugin for monitoring a Shoutcast 2.0.x Server (Multigraph) |
|
| 6 |
|
|
| 7 |
=head1 Munin Configuration |
|
| 8 |
|
|
| 9 |
[shoutcast2_multi] |
|
| 10 |
env.host 127.0.0.1 *default* |
|
| 11 |
env.port 8000 *default* |
|
| 12 |
env.pass changeme *default* |
|
| 13 |
|
|
| 14 |
=head2 Munin Configuration Explanation |
|
| 15 |
|
|
| 16 |
host = host we are attempting to connection to, can be ip, or hostname |
|
| 17 |
port = port we need to connect to in order to get to admin.cgi |
|
| 18 |
pass = password to use to authenticate as admin user |
|
| 19 |
|
|
| 20 |
=head1 License |
|
| 21 |
|
|
| 22 |
GPLv2 |
|
| 23 |
|
|
| 24 |
=head1 Magic Markers |
|
| 25 |
|
|
| 26 |
#%# family=auto |
|
| 27 |
#%# capabilities=autoconf |
|
| 28 |
|
|
| 29 |
=cut |
|
| 30 |
|
|
| 31 |
use strict; |
|
| 32 |
use warnings; |
|
| 33 |
use LWP::UserAgent; |
|
| 34 |
use XML::Simple; |
|
| 35 |
use Munin::Plugin; |
|
| 36 |
|
|
| 37 |
need_multigraph(); |
|
| 38 |
|
|
| 39 |
=head1 Variable Declarations |
|
| 40 |
|
|
| 41 |
This section is mainly for importing / declaring our environment variables. |
|
| 42 |
This is were we will import the data from our plugin-conf.d file so we can |
|
| 43 |
override the default settings which will only work for Shoutcast test configs. |
|
| 44 |
|
|
| 45 |
=cut |
|
| 46 |
|
|
| 47 |
my $host = $ENV{host} || '127.0.0.1';
|
|
| 48 |
my $port = $ENV{port} || 8000;
|
|
| 49 |
my $pass = $ENV{pass} || 'changeme';
|
|
| 50 |
|
|
| 51 |
# Initialize hashref for storing results information... |
|
| 52 |
my $dataRef; |
|
| 53 |
|
|
| 54 |
# Create a hashref for our graph information that we will call up later... |
|
| 55 |
my $graphsRef; |
|
| 56 |
|
|
| 57 |
my $ua = LWP::UserAgent->new(); |
|
| 58 |
$ua->agent('Munin Shoutcast Plugin/0.1');
|
|
| 59 |
$ua->timeout(5); |
|
| 60 |
$ua->credentials($host.':'.$port, 'Shoutcast Server', 'admin'=>$pass); |
|
| 61 |
|
|
| 62 |
=head1 Graphs Declarations |
|
| 63 |
|
|
| 64 |
The following section of code contains our graph information. This is the data |
|
| 65 |
provided to Munin, so that it may properly draw our graphs based on the values |
|
| 66 |
the plugin returns. |
|
| 67 |
|
|
| 68 |
While you are free to change colors or labels changing the type, min, or max |
|
| 69 |
could cause unfortunate problems with your graphs. |
|
| 70 |
|
|
| 71 |
=cut |
|
| 72 |
|
|
| 73 |
$graphsRef->{active} = {
|
|
| 74 |
config => {
|
|
| 75 |
args => '--base 1000 --lower-limit 0', |
|
| 76 |
vlabel => 'Is a DJ Actively Connected?', |
|
| 77 |
category => 'shoutcast2', |
|
| 78 |
title => 'Active States', |
|
| 79 |
info => 'This graph shows us the active state or not, depending on if a DJ is connected', |
|
| 80 |
}, |
|
| 81 |
datasrc => [ |
|
| 82 |
{ name => 'active', draw => 'AREA', min => '0', max => '1', label => 'On or Off', type => 'GAUGE' },
|
|
| 83 |
], |
|
| 84 |
}; |
|
| 85 |
|
|
| 86 |
$graphsRef->{listeners} = {
|
|
| 87 |
config => {
|
|
| 88 |
args => '--base 1000 --lower-limit 0', |
|
| 89 |
vlabel => 'Listener Count', |
|
| 90 |
category => 'shoutcast2', |
|
| 91 |
title => 'Listeners', |
|
| 92 |
info => 'This graph shows us the various counts for listener states we are tracking', |
|
| 93 |
}, |
|
| 94 |
datasrc => [ |
|
| 95 |
{ name => 'maxlisteners', draw => 'STACK', min => '0', label => 'Max Listeners', type => 'GAUGE' },
|
|
| 96 |
{ name => 'currlisteners', draw => 'AREA', min => '0', label => 'Current Listeners', type => 'GAUGE' },
|
|
| 97 |
], |
|
| 98 |
}; |
|
| 99 |
|
|
| 100 |
$graphsRef->{sid_active} = {
|
|
| 101 |
config => {
|
|
| 102 |
args => '--base 1000 --lower-limit 0', |
|
| 103 |
vlabel => 'Is a DJ Actively Connected?', |
|
| 104 |
title => 'Active State', |
|
| 105 |
info => 'This graph shows us the active state or not, depending on if a DJ is connected', |
|
| 106 |
}, |
|
| 107 |
datasrc => [ |
|
| 108 |
{ name => 'active', draw => 'AREA', min => '0', max => '1', label => 'On or Off', type => 'GAUGE', xmlkey => 'STREAMSTATUS' },
|
|
| 109 |
], |
|
| 110 |
}; |
|
| 111 |
|
|
| 112 |
$graphsRef->{sid_listeners} = {
|
|
| 113 |
config => {
|
|
| 114 |
args => '--base 1000 --lower-limit 0', |
|
| 115 |
vlabel => 'Listener Count', |
|
| 116 |
title => 'Listeners', |
|
| 117 |
info => 'This graph shows us the various counts for listener states we are tracking', |
|
| 118 |
}, |
|
| 119 |
datasrc => [ |
|
| 120 |
{ name => 'maxlisteners', draw => 'STACK', min => '0', label => 'Max Listeners', type => 'GAUGE', xmlkey => 'MAXLISTENERS' },
|
|
| 121 |
{ name => 'currlisteners', draw => 'AREA', min => '0', label => 'Current Listeners', type => 'GAUGE', xmlkey => 'CURRENTLISTENERS' },
|
|
| 122 |
{ name => 'peaklisteners', draw => 'LINE2', min => '0', label => 'Peak Listeners', type => 'GAUGE', xmlkey => 'PEAKLISTENERS' },
|
|
| 123 |
{ name => 'uniqlisteners', draw => 'LINE2', min => '0', label => 'Unique Listeners', type => 'GAUGE', xmlkey => 'UNIQUELISTENERS' },
|
|
| 124 |
], |
|
| 125 |
}; |
|
| 126 |
|
|
| 127 |
if (defined($ARGV[0]) && ($ARGV[0] eq 'config')) {
|
|
| 128 |
config(); |
|
| 129 |
exit; |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
if (defined($ARGV[0]) && ($ARGV[0] eq 'autoconf')) {
|
|
| 133 |
check_autoconf(); |
|
| 134 |
exit; |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
# I guess we are collecting stats to return, execute main subroutine. |
|
| 138 |
main(); |
|
| 139 |
|
|
| 140 |
exit; |
|
| 141 |
|
|
| 142 |
sub main {
|
|
| 143 |
my ($returnBit,$adminRef) = fetch_admin_data($ua,$host,$port); |
|
| 144 |
if ($returnBit == 0) {
|
|
| 145 |
exit; |
|
| 146 |
} |
|
| 147 |
my $streamConfigRef = $adminRef->{STREAMCONFIGS}->{STREAMCONFIG};
|
|
| 148 |
my $sidDataRef; |
|
| 149 |
foreach my $sid (keys %{$streamConfigRef}) {
|
|
| 150 |
my ($return,$tmpSidRef) = fetch_sid_data($sid); |
|
| 151 |
if ($return == 0) {
|
|
| 152 |
next; |
|
| 153 |
} |
|
| 154 |
$sidDataRef->{$sid} = $tmpSidRef;
|
|
| 155 |
} |
|
| 156 |
print_active_data($sidDataRef); |
|
| 157 |
print_listener_data($adminRef->{STREAMCONFIGS}->{SERVERMAXLISTENERS}, $sidDataRef);
|
|
| 158 |
return; |
|
| 159 |
} |
|
| 160 |
|
|
| 161 |
sub print_active_data {
|
|
| 162 |
my ($sidDataRef) = (@_); |
|
| 163 |
my $globalActive = 0; |
|
| 164 |
foreach my $sid (sort keys %{$sidDataRef}) {
|
|
| 165 |
print "multigraph shoutcast2_active.active_sid_$sid\n"; |
|
| 166 |
foreach my $dsrc (@{$graphsRef->{sid_active}->{datasrc}}) {
|
|
| 167 |
print "$dsrc->{name}.value $sidDataRef->{$sid}->{$dsrc->{xmlkey}}\n";
|
|
| 168 |
if ($sidDataRef->{$sid}->{$dsrc->{xmlkey}} == 1) {
|
|
| 169 |
$globalActive = 1; |
|
| 170 |
} |
|
| 171 |
} |
|
| 172 |
} |
|
| 173 |
print "multigraph shoutcast2_active\n"; |
|
| 174 |
foreach my $dsrc (@{$graphsRef->{active}->{datasrc}}) {
|
|
| 175 |
print "$dsrc->{name}.value $globalActive\n";
|
|
| 176 |
} |
|
| 177 |
return; |
|
| 178 |
} |
|
| 179 |
|
|
| 180 |
sub print_listener_data {
|
|
| 181 |
my ($maxListeners,$sidDataRef) = (@_); |
|
| 182 |
my $globalListeners = 0; |
|
| 183 |
foreach my $sid (sort keys %{$sidDataRef}) {
|
|
| 184 |
print "multigraph shoutcast2_listeners.listeners_sid_$sid\n"; |
|
| 185 |
foreach my $dsrc (@{$graphsRef->{sid_listeners}->{datasrc}}) {
|
|
| 186 |
print "$dsrc->{name}.value $sidDataRef->{$sid}->{$dsrc->{xmlkey}}\n";
|
|
| 187 |
if ($dsrc->{name} eq 'currlisteners') {
|
|
| 188 |
$globalListeners += $sidDataRef->{$sid}->{$dsrc->{xmlkey}};
|
|
| 189 |
} |
|
| 190 |
} |
|
| 191 |
} |
|
| 192 |
print "multigraph shoutcast2_active\n"; |
|
| 193 |
foreach my $dsrc (@{$graphsRef->{listeners}->{datasrc}}) {
|
|
| 194 |
if ($dsrc->{name} eq 'maxlisteners') {
|
|
| 195 |
print "$dsrc->{name}.value $maxListeners\n";
|
|
| 196 |
} else {
|
|
| 197 |
print "$dsrc->{name}.value $globalListeners\n";
|
|
| 198 |
} |
|
| 199 |
} |
|
| 200 |
return; |
|
| 201 |
} |
|
| 202 |
|
|
| 203 |
sub config {
|
|
| 204 |
my ($returnBit,$adminRef) = fetch_admin_data($ua,$host,$port); |
|
| 205 |
if ($returnBit == 0) {
|
|
| 206 |
# $adminRef returned a string, we'll just print it out. |
|
| 207 |
print "no (error response: $adminRef)\n"; |
|
| 208 |
exit; |
|
| 209 |
} |
|
| 210 |
my $streamConfigRef = $adminRef->{STREAMCONFIGS}->{STREAMCONFIG};
|
|
| 211 |
my $sidDataRef; |
|
| 212 |
foreach my $sid (keys %{$streamConfigRef}) {
|
|
| 213 |
my ($return,$tmpSidRef) = fetch_sid_data($sid); |
|
| 214 |
if ($return == 0) {
|
|
| 215 |
next; |
|
| 216 |
} |
|
| 217 |
$sidDataRef->{$sid} = $tmpSidRef;
|
|
| 218 |
} |
|
| 219 |
print_active_config($sidDataRef); |
|
| 220 |
print_listener_config($sidDataRef); |
|
| 221 |
return; |
|
| 222 |
} |
|
| 223 |
|
|
| 224 |
sub print_active_config {
|
|
| 225 |
my ($sidDataRef) = (@_); |
|
| 226 |
foreach my $sid (sort keys %{$sidDataRef}) {
|
|
| 227 |
# Print the Config Info First |
|
| 228 |
print "multigraph shoutcast2_active.active\_sid\_$sid\n"; |
|
| 229 |
print "graph_title ".$graphsRef->{sid_active}->{config}->{title}." for StreamID: $sid\n";
|
|
| 230 |
print "graph_args ".$graphsRef->{sid_active}->{config}->{args}."\n";
|
|
| 231 |
print "graph_vlabel ".$graphsRef->{sid_active}->{config}->{vlabel}."\n";
|
|
| 232 |
print "graph_category streamid_$sid\n"; |
|
| 233 |
print "graph_info ".$graphsRef->{sid_active}->{config}->{info}."\n";
|
|
| 234 |
# Print the Data Value Info |
|
| 235 |
foreach my $dsrc (@{$graphsRef->{sid_active}->{datasrc}}) {
|
|
| 236 |
while ( my ($key, $value) = each (%{$dsrc})) {
|
|
| 237 |
next if ($key eq 'name'); |
|
| 238 |
next if ($key eq 'xmlkey'); |
|
| 239 |
print "$dsrc->{name}.$key $value\n";
|
|
| 240 |
} |
|
| 241 |
} |
|
| 242 |
} |
|
| 243 |
print "multigraph shoutcast2_active\n"; |
|
| 244 |
print "graph_title ".$graphsRef->{active}->{config}->{title}."\n";
|
|
| 245 |
print "graph_args ".$graphsRef->{active}->{config}->{args}."\n";
|
|
| 246 |
print "graph_vlabel ".$graphsRef->{active}->{config}->{vlabel}."\n";
|
|
| 247 |
print "graph_category".$graphsRef->{active}->{config}->{category}."\n";
|
|
| 248 |
print "graph_info ".$graphsRef->{active}->{config}->{info}."\n";
|
|
| 249 |
# Print the Data Value Info |
|
| 250 |
foreach my $dsrc (@{$graphsRef->{active}->{datasrc}}) {
|
|
| 251 |
while ( my ($key, $value) = each (%{$dsrc})) {
|
|
| 252 |
next if ($key eq 'name'); |
|
| 253 |
print "$dsrc->{name}.$key $value\n";
|
|
| 254 |
} |
|
| 255 |
} |
|
| 256 |
return; |
|
| 257 |
} |
|
| 258 |
|
|
| 259 |
sub print_listener_config {
|
|
| 260 |
my ($sidDataRef) = (@_); |
|
| 261 |
foreach my $sid (sort keys %{$sidDataRef}) {
|
|
| 262 |
# Print the Config Info First |
|
| 263 |
print "multigraph shoutcast2_listeners.listeners\_sid\_$sid\n"; |
|
| 264 |
print "graph_title ".$graphsRef->{sid_listeners}->{config}->{title}." for StreamID: $sid\n";
|
|
| 265 |
print "graph_args ".$graphsRef->{sid_listeners}->{config}->{args}."\n";
|
|
| 266 |
print "graph_vlabel ".$graphsRef->{sid_listeners}->{config}->{vlabel}."\n";
|
|
| 267 |
print "graph_category streamid_$sid\n"; |
|
| 268 |
print "graph_info ".$graphsRef->{sid_listeners}->{config}->{info}."\n";
|
|
| 269 |
# Print the Data Value Info |
|
| 270 |
foreach my $dsrc (@{$graphsRef->{sid_listeners}->{datasrc}}) {
|
|
| 271 |
while ( my ($key, $value) = each (%{$dsrc})) {
|
|
| 272 |
next if ($key eq 'name'); |
|
| 273 |
next if ($key eq 'xmlkey'); |
|
| 274 |
print "$dsrc->{name}.$key $value\n";
|
|
| 275 |
} |
|
| 276 |
} |
|
| 277 |
} |
|
| 278 |
print "multigraph shoutcast2_listeners\n"; |
|
| 279 |
print "graph_title ".$graphsRef->{listeners}->{config}->{title}."\n";
|
|
| 280 |
print "graph_args ".$graphsRef->{listeners}->{config}->{args}."\n";
|
|
| 281 |
print "graph_vlabel ".$graphsRef->{listeners}->{config}->{vlabel}."\n";
|
|
| 282 |
print "graph_category".$graphsRef->{listeners}->{config}->{category}."\n";
|
|
| 283 |
print "graph_info ".$graphsRef->{listeners}->{config}->{info}."\n";
|
|
| 284 |
# Print the Data Value Info |
|
| 285 |
foreach my $dsrc (@{$graphsRef->{listeners}->{datasrc}}) {
|
|
| 286 |
while ( my ($key, $value) = each (%{$dsrc})) {
|
|
| 287 |
next if ($key eq 'name'); |
|
| 288 |
print "$dsrc->{name}.$key $value\n";
|
|
| 289 |
} |
|
| 290 |
} |
|
| 291 |
return; |
|
| 292 |
} |
|
| 293 |
|
|
| 294 |
sub check_autoconf {
|
|
| 295 |
my ($returnBit,$adminRef) = fetch_admin_data($ua,$host,$port); |
|
| 296 |
if ($returnBit == 0) {
|
|
| 297 |
# $adminRef returned a string, we'll just print it out. |
|
| 298 |
print "no (error response: $adminRef)\n"; |
|
| 299 |
} else {
|
|
| 300 |
print "yes\n"; |
|
| 301 |
} |
|
| 302 |
return; |
|
| 303 |
} |
|
| 304 |
|
|
| 305 |
sub fetch_sid_data {
|
|
| 306 |
my ($sid) = (@_); |
|
| 307 |
my $url = 'http://'.$host.':'.$port.'/stats?sid='.$sid; |
|
| 308 |
my $response = $ua->get($url); |
|
| 309 |
if ($response->is_success) {
|
|
| 310 |
my $returnRef = XMLin($response->decoded_content); |
|
| 311 |
return (1, $returnRef); |
|
| 312 |
} else {
|
|
| 313 |
return (0, $response->status_line); |
|
| 314 |
} |
|
| 315 |
} |
|
| 316 |
|
|
| 317 |
sub fetch_admin_data {
|
|
| 318 |
my $url = 'http://'.$host.':'.$port.'/admin.cgi?sid=1&mode=viewxml&page=6'; |
|
| 319 |
my $response = $ua->get($url); |
|
| 320 |
if ($response->is_success) {
|
|
| 321 |
my $returnRef = XMLin($response->decoded_content); |
|
| 322 |
if (($returnRef->{STREAMCONFIGS}->{TOTALCONFIGS} > 0) && (defined($returnRef->{STREAMCONFIGS}->{STREAMCONFIG}))) {
|
|
| 323 |
return (1, $returnRef); |
|
| 324 |
} else {
|
|
| 325 |
return (0, 'Unable to Detect any Stream Configurations'); |
|
| 326 |
} |
|
| 327 |
} else {
|
|
| 328 |
return (0, $response->status_line); |
|
| 329 |
} |
|
| 330 |
} |
|
| 331 |
|
|
Formats disponibles : Unified diff