Commit 32470d8b authored by oak's avatar oak

ny versjon iptv med xml-basert output

parent 9765f110
# qstream jobs
5,15,25,35,45,55 * * * * qstream /usr/bin/qstream-mpeg.job
5,15,25,35,45,55 * * * * qstream /usr/bin/qstream-iptv.job
1 1 * * * /usr/bin/qstream-poll-list /etc/qstream/iptv/poll.cf
## 0 * * * * qstream /usr/bin/sap-test 3595
qstream usr/bin
qstream-tv usr/bin
qstream-tv.job usr/bin
qstream-iptv usr/bin
qstream-iptv.job usr/bin
qstream-mpeg usr/bin
qstream-mpeg.job usr/bin
qstream-check-bb usr/bin
qstream-poll-list usr/bin
sap-test usr/bin
rtmp/client.pm usr/share/perl5/rtmp
#!/usr/bin/perl
#
# process qstream log files and report to Xymon
use XML::Simple;
use Data::Dumper;
# use Socket;
# use IO::Select;
# use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
# use DateTime;
require "newgetopt.pl";
@opts=( 'bb=s', 'debug', 'dump', 'v', 'h', 'help' );
my $usage="Usage $0 [-debug] [-v] [-h]
-bb <hostname> - XYMON/BB host to receive reports
";
my $rc=&NGetOpt(@opts);
die $usage if not $rc or $opt_h or $opt_help;
my $bb_host = $opt_bb || `hostname -f`;
my $report_host = `hostname -f`;
$span_limit=[0,1,9]; # sec
$bw_limit=[0,2000000, 30000]; # bps
$jitter_limit=[0, 5, 10 ]; # ms
$loss_limit=[0, 0.1, 1 ]; # %
$bb_color=["red", "yellow", "green"];
@r_color= reverse(@$bb_color);
$rev_color= \@r_color;
$call_limit=[0,70,90]; # call succes in percent
# our $tz=DateTime::TimeZone->new( name => 'local' );
foreach $flow_file(@ARGV){
process_flow($flow_file);
}
exit(0);
#--------------------------------------------------------------------------------
sub process_flow {
my $file=shift;
my $xml = XMLin($file, ForceArray => 0 );
if ( $xml){ # successful parsing
foreach $flow ( $xml->{flow}){
&bb_report("Response", $flow->{flow_name}, bb_color($span_limit, $bb_color, $flow->{span}), $flow->{span} );
&bb_report("Jitter", $flow->{flow_name}, bb_color($jitter_limit, $rev_color, $flow->{pcr_jitter}->{pcr_jitter_avg}),
$flow->{pcr_jitter}->{pcr_jitter_avg} );
my $loss_rate=0;
if ( $flow->{transport}->{mpeg_packets} > 0){
$loss_rate=100 * $flow->{transport}->{mpeg_lost_packets} / $flow->{transport}->{mpeg_packets};
}
&bb_report("Loss", $flow->{flow_name}, bb_color($loss_limit, $rev_color, $loss_rate ), $loss_rate );
}
}
}
#--------------------------------------------------------------------------------
sub bb_color {
my ($limit, $color, $value)=@_;
for ($i=$#$limit;$i>=$[;$i--){
if ( $value >= @$limit[$i]){
return @$color[$i];
}
}
}
sub bb_report {
return 0 if $opt_f && ! $at_end_of_file;
my ($bbtest, $machine, $color, $msg)=@_;
# my $cmd="/usr/lib/hobbit/client/bin/bb $bb_host 'status $machine.$bbtest $color $msg\n'>>$ENV{HOME}/cmd.log 2>&1";
my $cmd="/usr/lib/hobbit/client/bin/bb $bb_host 'status $machine.$bbtest $color $msg\n'";
# system($cmd)|| warn "Command failed : $cmd : $!";
my @cmd=("/usr/lib/hobbit/client/bin/bb", "$bb_host", "status $machine.$bbtest $color $msg\n");
system(@cmd) if $opt_bb; # || warn "Command failed : @cmd : $!" ;
print $cmd, "\n" if $opt_v;
}
# hh:mm:ss to seconds
sub to_sec {
my ($hh, $mm, $ss,$ms)=split(/:/, shift);
return (3600*$hh+60*$mm+$ss+$ms/1000);
}
#!/bin/bash
ulimit -c unlimited # for debugging of hangup problem og qstream
y=`date +%Y`
m=`date +%m`
d=`date +%d`
h=`date +%H`
tv=/var/lib/qstream/data/tv
ydir=$tv/$y
test -d $ydir || mkdir $ydir
mdir=$ydir/$m
test -d $mdir || mkdir $mdir
ddir=$mdir/$d
test -d $ddir || mkdir $ddir
#hdir=$ddir/$h
#test -d $hdir || mkdir $hdir
# tmp=$tv/data/tmp/$$
# test -d $tmp || mkdir $tmp
cd $ddir
export IFS=";"
# export MALLOC_CHECK_=1 # write comprehensive error message when fail
ulimit -c 500000000
while read kanal mcaddr opt rest; do
echo $kanal | egrep -q '^\s*#'
if test $? = 1 ; then # no comment
log=`echo $kanal | sed -e 's/ /_/g'`
xml=$log.`date +%T`.xml
/usr/bin/qstream -name "$kanal" -xml "$xml" -q -last 10 -nperiod 1 -net $opt $mcaddr >> $log.log 2>>$log.error
if test $? != 0 ; then # possible error - add CR
echo >> $log.log
fi
/usr/bin/qstream-check-bb -bb 158.38.130.84 "$xml"
if test ! -s $log.log ; then rm $log.log ; fi
if test ! -s $log.error ; then rm $log.error ; fi
fi
done
/usr/bin/qstream-iptv < /etc/qstream/iptv/etc/poll.cf
#!/bin/sh
dest=$1
tmp=/tmp/poll.cf.new$$
curl -s http://forskningsnett.uninett.no/tv/playlist.html \
| perl -ne 'if(/^#EXTINF:.*,(.*)/){$n=$1; $n=~s/\W/_/g} elsif (/^\w/){chomp;if(/239.1.1/){$op="Snap"} elsif (/233.155.107/){$op="TV2"} else{$op="Div"};printf "%s_%s;%s;-mpeg\n", $op, $n, $_}' | grep -v -f /local/net-status/iptv/etc/nopoll.cf > $tmp
if test -s $tmp; then
# ci -q -l -mauto /local/net-status/iptv/etc/poll.cf0
mv $tmp $dest
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment