Skip to content
Snippets Groups Projects
Commit f1f2d3f0 authored by Sergey Joseph Ivanov's avatar Sergey Joseph Ivanov
Browse files

monitor how many DSes failed in Cacti last run

parent 297cced3
No related branches found
No related tags found
No related merge requests found
package Site::Cacti;
use strict;
use warnings;
use base 'Resmon::Module';
use Resmon::ExtComm qw(run_command cache_command);
=pod
=head1 Site::Cacti
Site::Cacti is a Cacti log parser to summarize failed datasets number
=head1 SYNOPSIS
Site::Command {
some_check_name: noop;
}
=head1 DESCRIPTION
This module parses Cacti Log and gets total numbers of Datasets and
how many of them failed during last cacti run.
=head1 CONFIGURATION
=over
=item check_name
=back
=cut
my $DEBUG=0;
sub handler {
my $self = shift;
my $config = $self->{config}; # All configuration is in here
my $check_name = $self->{check_name}; # The check name is in here
my $SPAN=(5*60); # seconds
my $LOG='/var/log/cacti/cacti.log';
my $END=`tail -1 $LOG`; chomp $END;
$END = $END =~ m<^(\d{4}/\d{1,2}/\d{1,2} \d\d:\d\d)> ? $1 :
die "problem with tail $LOG: strange date/time in the line \n $END";
my $M = substr $END, -1;
$M = $M < 5 ? 0 : 5;
my $START=$END;
$START =~ s/.$/$M/;
open (my $log, "<$LOG") or die "can't open <$LOG: $!";
=pod example of the log line:
2018/11/02 14:45:05 - SPINE: Poller[1] Device[14] TH[1] DS[1341] SNMP: v2: 172.26.69.124, dsname: traffic_out, oid: .1.3.6.1.2.1.31.1.1.1.10.669, value: 93577117
=cut
while (<$log>) {
last if($_ =~ m<^$START>);
}
my ($errors,$datasets) = (0,0);
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 += $2;
}
=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;
}
}
close $log;
return {
"datasets" => [$datasets,"i"],
"errors" => [$errors, "i"],
};
};
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment