Advertisement
teuk

icecastListeners

Oct 7th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.77 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use diagnostics;
  6. use JSON;
  7.  
  8. sub getNbListeners(@);
  9.  
  10. print getNbListeners("localhost",15000);
  11.  
  12. exit 0;
  13.  
  14. sub getNbListeners(@) {
  15.         my ($hostname,$port) = @_;
  16.         unless (open ICECAST_STATUS_JSON, "curl -f -s http://$hostname:$port/status-json.xsl |") {
  17.                 return 0;
  18.         }
  19.         my $line;
  20.         if (defined($line=<ICECAST_STATUS_JSON>)) {
  21.                 chomp($line);
  22.                 my $json = decode_json $line;
  23.                 my @sources = @{$json->{'icestats'}{'source'}};
  24.                 my $listeners = 0;
  25.                 foreach my $infos (@sources) {
  26.                         $listeners += %{$infos}{'listeners'};
  27.                 }
  28.                 return $listeners
  29.         }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement