From 14c194723f801921c9f215b58eb013e806d83bc2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 13 Feb 2020 14:28:41 +0100 Subject: [PATCH] fix 0 uptime value --- centreon-plugins/centreon/plugins/misc.pm | 4 +++ centreon-plugins/snmp_standard/mode/uptime.pm | 28 ++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index c55cafc3c..67028cdb7 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -392,6 +392,10 @@ sub change_seconds { $str_append = ' '; } + if ($str eq '') { + $str = $options{value}; + $str .= $options{start} if (defined($options{start})); + } return $str; } diff --git a/centreon-plugins/snmp_standard/mode/uptime.pm b/centreon-plugins/snmp_standard/mode/uptime.pm index 127d0aff4..ffd331f93 100644 --- a/centreon-plugins/snmp_standard/mode/uptime.pm +++ b/centreon-plugins/snmp_standard/mode/uptime.pm @@ -33,16 +33,16 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - "force-oid:s" => { name => 'force_oid' }, - "check-overload" => { name => 'check_overload' }, - "reboot-window:s" => { name => 'reboot_window', default => 5000 }, - "unit:s" => { name => 'unit', default => 's' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'force-oid:s' => { name => 'force_oid' }, + 'check-overload' => { name => 'check_overload' }, + 'reboot-window:s' => { name => 'reboot_window', default => 5000 }, + 'unit:s' => { name => 'unit', default => 's' }, }); - + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; } @@ -64,7 +64,7 @@ sub check_options { if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) { $self->{option_results}->{unit} = 's'; } - + $self->{statefile_cache}->check_options(%options); } @@ -119,12 +119,14 @@ sub run { $value = $result->{$oid_sysUpTime}; } } - + $value = $self->check_overload(timeticks => $value); $value = floor($value / 100); - - my $exit_code = $self->{perfdata}->threshold_check(value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + my $exit_code = $self->{perfdata}->threshold_check( + value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); $self->{output}->perfdata_add( label => 'uptime', unit => $self->{option_results}->{unit}, value => floor($value / $unitdiv->{$self->{option_results}->{unit}}),