diff --git a/lib/Site/Cacti.pm b/lib/Site/Cacti.pm index 1d1854afa103d3e4b3d8c4d09824dd47839afc08..388f87d7facffc64936088274c665d569fd53d7f 100644 --- a/lib/Site/Cacti.pm +++ b/lib/Site/Cacti.pm @@ -36,6 +36,7 @@ how many of them failed during last cacti run. my $DEBUG=0; +my $SLEEP=5; sub handler { my $self = shift; @@ -57,27 +58,54 @@ sub handler { while (<$log>) { last if($_ =~ m<^$START>); } - my ($errors,$datasets) = (0,0); - while (<$log>) { + my ($errors,$items,$hosts,$rrds,$datasets,$complete,$time,$error) = (0,0,0,0,0,0,0.0,''); + until ($complete) { + while (<$log>) { =pod example of errors reported: 2018/11/02 17:00:05 - SPINE: Poller[1] WARNING: Invalid Response(s), Errors[1] Device[9] Thread[1] DS[903] =cut - if(/SPINE:\s+Poller\[\d+\]\s+WARNING:.*Errors\[(\d+)\]\s+Device\[(\d+)\].*\s+DS\[([ 0-9,]+)\]/) { - print STDERR "errors: num=$1, Device\[$2], DSes=$3\n" if $DEBUG; - $errors += $1; - } + if(/SPINE:\s+Poller\[\d+\]\s+WARNING:.*Errors\[(\d+)\]\s+Device\[(\d+)\].*\s+DS\[([ 0-9,]+)\]/) { + print STDERR "errors: num=$1, Device\[$2], DSes=$3\n" if $DEBUG; + $errors += $1; + } =pod example of DSes reported: 2018/11/05 15:00:05 - SPINE: Poller[1] Device[32] TH[1] NOTE: There are '398' Polling Items for this Device =cut - elsif(/SPINE:\s+Poller\[\d+\]\s+Device\[(\d+)\]\s+TH\[\d+\]\s+NOTE: There are '(\d+)' Polling Items for this Device/) { - $datasets += $2; - print STDERR "There are $2 datasets for Device\[$1\]\n" if $DEBUG; - } + elsif(/SPINE:\s+Poller\[\d+\]\s+Device\[(\d+)\]\s+TH\[\d+\]\s+NOTE: There are '(\d+)' Polling Items for this Device/) { + $hosts += 1; + $items += $2; + print STDERR "There are $2 items for Device\[$1\]\n" if $DEBUG; + } +=pod example of the line to be expected at the end: +2018/11/07 00:00:06 - SYSTEM STATS: Time:5.4350 Method:spine Processes:2 Threads:2 Hosts:56 HostsPerProcess:28 DataSources:9131 RRDsProcessed:3323 +=cut + elsif(/\s+SYSTEM STATS:\s+Time:([\d.]*)\s+.*Hosts:(\d+)\s+.*DataSources:(\d+)\s+.*RRDsProcessed:(\d+)/) { + ($time,$hosts,$datasets,$rrds,$complete) = ($1,$2,$3,$4,1); + print STDERR "SYSTEM STATS: time=$time, hosts=$hosts, datasources=$datasets, rrds=$rrds\n" if $DEBUG; + } +=pod example of the failure line to be expected at the end: +2018/11/07 12:30:07 - PHPSVR ERROR: Input Expected, Script Server Terminating +=cut + elsif(/\s+PHPSVR ERROR:.*Script Server Terminating/) { + chomp; + ($time,$complete,$error) = ($SPAN,1,$_); + print STDERR "ERROR: $_" if $DEBUG; + } + } + if (not $complete) { + sleep $SLEEP; + $log->clearerr(); + } } close $log; return { - "datasets" => [$datasets,"i"], - "errors" => [$errors, "i"], + "time" => [$time, "n"], + "hosts" => [$hosts, "i"], + "rrds" => [$rrds, "i"], + "items" => [$items, "i"], + "datasets" => [$datasets,"i"], + "errors" => [$errors, "i"], + "error" => [$error, "s"], }; };