| 1 | 1 | simandl | package HotSaNICmod::OSdep; |
| 2 | | | |
| 3 | | | use RRDs; |
| 4 | | | use LWP::Simple; |
| 5 | | | |
| 6 | | | sub version { |
| 7 | | | ($VERSION = '$Revision: 1.15 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 8 | | | return "default.pm $VERSION"; |
| 9 | | | } |
| 10 | | | |
| 11 | | | sub sample { |
| 12 | | | my %args=@_; |
| 13 | | | |
| 14 | | | foreach my $item (@{$args{STREAM}}) { |
| 15 | | | my ($url,$description)=split /,/,$item; |
| 16 | | | ($name=$url) =~ s/http\:\/\///g; |
| 17 | | | $name =~ s/\//_/g; |
| 18 | | | $name =~ s/:/_/g; |
| 19 | | | |
| 20 | | | my $users=0; |
| 21 | | | my $unique=0; |
| 22 | | | my $bandwidth=0; |
| 23 | | | my $line=""; |
| 24 | | | |
| 25 | | | if ( ($args{METHOD} eq "lynx") || ( $url =~ ":") ) { |
| 26 | | | open LINES,"lynx -width 200 -dump $url|"; |
| 27 | | | while (<LINES>) { if (/listeners/) { $line=$_; last; } } |
| 28 | | | close LINES; |
| 29 | | | } |
| 30 | | | else { |
| 31 | | | my @contents=split /\n|<[Bb][Rr]>/,LWP::Simple::get($url); |
| 32 | | | foreach (@contents) { if (/listeners/) { s/<.*?>//g; $line=$_; last; } } |
| 33 | | | } |
| 34 | | | |
| 35 | | | if ($line ne "") { |
| 36 | | | $line =~ /at (\d+) kbps/, $bandwidth=$1; |
| 37 | | | $line =~ /with (\d+) of/, $users=$1; |
| 38 | | | $line =~ /\((\d+) uniq/, $unique=$1; |
| 39 | | | } |
| 40 | | | |
| 41 | | | HotSaNICmod::do_rrd($name,"U",time,$users,$unique); |
| 42 | | | |
| 43 | | | } |
| 44 | | | } |
| 45 | | | |
| 46 | | | 1; |
| 47 | | | |
| 48 | | | # Stream Status: Stream is up at 128 kbps with 0 of 5 listeners (0 unique) |
| 49 | | | # Stream Status: Stream is up at 64 kbps with 21 of 32 listeners (20 unique) |