Newer
Older
#!/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;
use Getopt::Long;
@opts=( 'bb=s' => \$opt_bb, 'debug' => \$opt_debug, 'dump' => \$opt_dump, 'v' => \$opt_v, 'h' => \$opt_h, 'help' => \$opt_help);
my $usage="Usage $0 [-debug] [-v] [-h]
-bb <hostname> - XYMON/BB host to receive reports
";
die $usage if not $rc or $opt_h or $opt_help;
my $bb_host = $opt_bb || `hostname -f`;
chomp($bb_host);
my $report_host = `hostname -s`;
chomp($report_host);
$span_limit=[0,1,9]; # sec
$bw_limit=[0,2000000, 30000]; # bps
$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}){
my $jratio=0;
if ($flow->{network_stats}->{gap_avg} > 0 ){
my $jratio= $flow->{pcr_jitter}->{pcr_jitter_avg} / $flow->{network_stats}->{gap_avg};
}
&bb_report("Response", $flow->{flow_name}, bb_color($span_limit, $bb_color, $flow->{span}), (sprintf "%.1f",$flow->{span}).'sec' );
&bb_report("Jitter", $flow->{flow_name}, bb_color($jitter_limit, $rev_color,$jratio),
(sprintf "%.1f",$flow->{pcr_jitter}->{pcr_jitter_avg}).'ms' );
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+35/group:$report_host $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);
}