initial import START
authorivan <ivan>
Mon, 21 Jan 2002 09:37:42 +0000 (09:37 +0000)
committerivan <ivan>
Mon, 21 Jan 2002 09:37:42 +0000 (09:37 +0000)
README [new file with mode: 0644]
icesnap [new file with mode: 0755]
icesnap.conf [new file with mode: 0644]
snap.tmpl [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..025f499
--- /dev/null
+++ b/README
@@ -0,0 +1,18 @@
+icesnap
+
+Copyright (c) 2002 Ivan Kohler
+All rights reserved.
+This program is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+ivan-icesnap@420.am
+
+icesnap takes a snapshot of the current state of an icecast server, then
+creates (from a template) HTML pages for each mountpoint listing the number
+of listeners, total and broken down by User-Agent (i.e. xmms, WinAMP,
+Realplayer, etc.).
+
+To use, set the parameters in icesnap.conf and copy it to /etc/icesnap.conf,
+then run icesnap as desired (perhaps from cron) to generate the HTML output.
+A sample template file is included in snap.tmpl
+
diff --git a/icesnap b/icesnap
new file mode 100755 (executable)
index 0000000..b56aa3b
--- /dev/null
+++ b/icesnap
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+#
+# Copyright (c) 2002 Ivan Kohler
+# All rights reserved.
+# This program is free software; you can redistribute it and/or modify it under
+# the same terms as Perl itself.
+#
+# ivan-icelog@420.am
+
+use strict;
+use Net::Icecast;
+use Apache::ASP;
+
+require "/etc/icesnap.conf";
+
+unless ( -e $outdir) {
+  mkdir($outdir, 0755) or die "can't mkdir $outdir: $!";
+}
+
+my $c = Net::Icecast->new($host, $port, $admin_password)
+  or die "can't connect";
+
+my %hash = $c->listeners;
+
+#my %mount;
+use vars qw( %mount );
+
+#produce blank pages
+foreach my $mount (qw( / /24 ) ) {
+  $mount{$mount} = {};
+}
+
+foreach my $listener ( keys %hash ) {
+#  print "$listener => \n";
+  my %lhash = %{$hash{$listener}};
+  foreach my $key ( keys %lhash ) {
+#    print "         $key => $lhash{$key}\n";
+  }
+
+  $mount{$lhash{mountpoint}}{$lhash{user_agent}}++; 
+}
+
+#print "\n\n";
+
+use vars qw($mount);
+foreach $mount ( keys %mount ) {
+  my $total = 0;
+  &writepage();
+#  print "$mount => \n";
+#  foreach my $user_agent ( keys %{$mount{$mount}} ) {
+#    $total += $mount{$mount}{$user_agent};
+#    print "        $user_agent => $mount{$mount}{$user_agent}\n";
+#  }
+#  print " TOTAL $total\n\n";
+}
+
+sub writepage {
+  #my $mount = shift;
+#  my %mount = %{shift()};
+  #my $mref = shift;
+
+  open(STDOUT,">$outdir/$mount.html") or die "can't open $outdir/$mount.html: $!";
+
+  #nicked from cgi/asp in the Apache::ASP disribution
+
+  my $r = &Apache::ASP::CGI::init($template);
+
+  $r->dir_config('NoHeaders', 1);
+
+  &Apache::ASP::handler($r);
+
+  close STDOUT;
+
+}
+
diff --git a/icesnap.conf b/icesnap.conf
new file mode 100644 (file)
index 0000000..0f9bf31
--- /dev/null
@@ -0,0 +1,16 @@
+
+# icecast server host
+my $host = 'server.name';
+
+# icecast server port number
+my $port = 8000;
+
+# icecast server admin password
+my $admin_password = 'adminpw';
+
+# template file
+my $template = '/path/to/snap.tmpl';
+
+# html output directory
+my $outdir = '/path/to/htmlout';
+
diff --git a/snap.tmpl b/snap.tmpl
new file mode 100644 (file)
index 0000000..ba12e8a
--- /dev/null
+++ b/snap.tmpl
@@ -0,0 +1,18 @@
+<html>
+  <head>
+    <title>icecast snapshot</title>
+  </head>
+  <body bgcolor="#e8e8e8">
+  <h2>icecast snapshot</h2>
+  Mountpoint: <%= $main::mount %><br><br>
+  <table border>
+    <tr><th>User Agent</th><th>#</th></tr>
+<% $total = 0;
+   foreach my $user_agent ( keys %{$main::mount{$main::mount}} ) {
+     $total += $main::mount{$main::mount}{$user_agent};
+%>
+    <tr><td><%= $user_agent %></td><td><%= $main::mount{$main::mount}{$user_agent} %></td></tr>
+<% } %>
+  </table>
+  <br>Total: <%= $total %><br>
+</html>