add an option to manage uptime overload

This commit is contained in:
qgarnier 2017-07-21 11:23:14 +02:00
parent 8c771fbb6e
commit 7d853f211c
4 changed files with 54 additions and 7 deletions

View File

@ -35,6 +35,7 @@ sub new {
'interfaces' => 'network::adva::fsp3000::snmp::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'snmp_standard::mode::memory',
'uptime' => 'snmp_standard::mode::uptime',
);
return $self;

View File

@ -35,6 +35,7 @@ sub new {
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::huawei::snmp::mode::memory',
'uptime' => 'snmp_standard::mode::uptime',
);
return $self;

View File

@ -36,6 +36,7 @@ sub new {
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'memory' => 'network::nokia::timos::snmp::mode::memory',
'uptime' => 'snmp_standard::mode::uptime',
);
return $self;

View File

@ -26,6 +26,8 @@ use strict;
use warnings;
use POSIX;
use centreon::plugins::misc;
use centreon::plugins::statefile;
use Time::HiRes qw(time);
sub new {
my ($class, %options) = @_;
@ -35,11 +37,13 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"force-oid:s" => { name => 'force_oid', },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"force-oid:s" => { name => 'force_oid' },
"check-overload" => { name => 'check_overload' },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
@ -55,6 +59,38 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_cache}->check_options(%options);
}
sub check_overload {
my ($self, %options) = @_;
return $options{timeticks} if (!defined($self->{option_results}->{check_overload}));
my $current_time = floor(time() * 100);
$self->{new_datas} = { last_time => $current_time, uptime => $options{timeticks}, overload => 0 };
$self->{statefile_cache}->read(statefile => "cache_" . $self->{snmp}->get_hostname() . '_' . $self->{snmp}->get_port() . '_' . $self->{mode});
my $old_uptime = $self->{statefile_cache}->get(name => 'uptime');
my $last_time = $self->{statefile_cache}->get(name => 'last_time');
my $overload = $self->{statefile_cache}->get(name => 'overload');
if (defined($old_uptime) && $old_uptime < $current_time) {
my $diff_time = $current_time - $last_time;
my $overflow = ($old_uptime + $diff_time) % 4294967296;
my $division = ($old_uptime + $diff_time) / 4294967296;
if ($division >= 1 &&
$overflow >= ($options{timeticks} - 5000) &&
$overflow <= ($options{timeticks} + 5000)) {
$overload++;
}
$options{timeticks} += ($overload * 4294967296);
}
$self->{new_datas}->{overload} = $overload if (defined($overload));
$self->{statefile_cache}->write(data => $self->{new_datas});
return $options{timeticks};
}
sub run {
@ -79,17 +115,20 @@ sub run {
}
}
my $exit_code = $self->{perfdata}->threshold_check(value => floor($value / 100),
$value = $self->check_overload(timeticks => $value);
$value = floor($value / 100);
my $exit_code = $self->{perfdata}->threshold_check(value => $value,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->perfdata_add(label => 'uptime', unit => 's',
value => floor($value / 100),
value => $value,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("System uptime is: %s",
centreon::plugins::misc::change_seconds(value => floor($value / 100), start => 'd')));
centreon::plugins::misc::change_seconds(value => $value, start => 'd')));
$self->{output}->display();
$self->{output}->exit();
@ -117,6 +156,11 @@ Threshold critical in seconds.
Can choose your oid (numeric format only).
=item B<--check-overload>
Uptime counter limit is 4294967296 and overflow.
With that option, we manage the counter going back. But there is a few chance we can miss a reboot.
=back
=cut