Commit a1904710 authored by Olav Kvittem's avatar Olav Kvittem

Added zabbix reporting and remove bb, small fix to qstream

parent 3c638177
#!/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;
use Date::Parse;
@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
";
my $rc=GetOptions(@opts);
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,3,9]; # sec
$bw_limit=[0,2000000, 30000]; # bps
$jitter_limit=[0, 2, 5 ]; # jitter_factor
$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
my $zfh;
if ($opt_dump){
$zfh=STDOUT;
} else {
open ($zfh, "|/usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf --with-timestamps --input-file -")
|| warn "Could not start zabbix_sender: $!";
}
# our $tz=DateTime::TimeZone->new( name => 'local' );
my @flow_files=@ARGV;
foreach $flow_file(@flow_files){
process_flow($flow_file);
}
exit(0);
#--------------------------------------------------------------------------------
sub process_flow {
my $file=shift;
my $xml = XMLin($file, ForceArray => 1 ) || warn "Could not process XML $file : $!";
my $base_file=`basename "$file"`;
chomp($base_file);
my $flow_name=$report_host.'.'.$base_file;
$flow_name=~s/(.\d\d){3}.xml$//; # remove .10:34:14.xml
if ( $xml){ # successful parsing
foreach $flow ( @{$xml->{flow}}){
# $flowif ( ref($flow) eq "ARRAY" );
if ($opt_v){ printf "Open flow $flow_name for $file\n"};
# my $flow_name=$report_host.'_'.$flow->{flow_name};
# $flow_name =~ tr/ /_aoaAOA/;
# $flow_name =~ tr/ \/;&|/_..../;
z( '', 'span' );
z( 'pcr_jitter', 'pcr_jitter_avg');
z( 'pcr_jitter', 'pcr_jitter_min');
z( 'pcr_jitter', 'pcr_jitter_max');
z( 'pcr_jitter', 'pcr_jitter_sdv');
z( 'network_stats', 'setuptime' );
z( 'network_stats', 'gap_avg' );
z( 'network_stats', 'gap_sdv' );
z( 'network_stats', 'gap_min' );
z( 'network_stats', 'gap_max' );
z( 'packet_stats', 'packet_count' );
z( 'bandwidth_stats', 'bandwidth_avg' );
z( 'bandwidth_stats', 'bandwidth_max' );
z( 'bandwidth_stats', 'bandwidth_max_100ms' );
z( 'bandwidth_stats', 'bandwidth_sdv' );
# anticiate just one transport stream (video).
z( 'transport_stream', 'pid' );
z( 'transport_stream', 'mpeg_packets' );
z( 'transport_stream', 'mpeg_lost_packets' );
z( 'transport_stream', 'media_loss_rate' );
z( 'transport_stream', 'media_bandwidth' );
z( 'transport_stream', 'dwell_avg' );
z( 'transport_stream', 'dwell_sdv' );
z( 'transport_stream', 'dwell_min' );
z( 'transport_stream', 'dwell_max' );
z( 'transport_stream', 'delay_factor' );
sub z{
my ($group, $var)=@_;
my $val;
if ( $group ){
$val = $flow->{$group}->[0]->{$var}->[0];
} else {
$val = $flow->{$var}->[0];
}
printf $zfh "%s uninett.iptv.%s %s %s\n", $flow_name, $var,
str2time($flow->{date}->[0] . 'T' . $flow->{time}->[0]), $val;
}
# close $zfh;
}
}
} # of process_flow
#--------------------------------------------------------------------------------
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);
}
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