Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use diagnostics;
- use JSON;
- sub getNbListeners(@);
- print getNbListeners("localhost",15000);
- exit 0;
- sub getNbListeners(@) {
- my ($hostname,$port) = @_;
- unless (open ICECAST_STATUS_JSON, "curl -f -s http://$hostname:$port/status-json.xsl |") {
- return 0;
- }
- my $line;
- if (defined($line=<ICECAST_STATUS_JSON>)) {
- chomp($line);
- my $json = decode_json $line;
- my @sources = @{$json->{'icestats'}{'source'}};
- my $listeners = 0;
- foreach my $infos (@sources) {
- $listeners += %{$infos}{'listeners'};
- }
- return $listeners
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement