fix exponential value for cisco thresholds

This commit is contained in:
garnier-quentin 2019-02-05 16:21:52 +01:00
parent 94525a03db
commit 42fa0a6b3a
2 changed files with 17 additions and 5 deletions

View File

@ -22,6 +22,7 @@ package centreon::common::cisco::standard::snmp::mode::components::sensor;
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::misc;
my %map_sensor_status = ( my %map_sensor_status = (
1 => 'ok', 1 => 'ok',
@ -140,8 +141,9 @@ sub get_default_warning_threshold {
} }
my $th = ''; my $th = '';
$th = $low_th . ':' if (defined($low_th)); $th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th));
$th .= $high_th if (defined($high_th)); $th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th));
return $th; return $th;
} }
@ -168,8 +170,9 @@ sub get_default_critical_threshold {
} }
my $th = ''; my $th = '';
$th = $low_th . ':' if (defined($low_th)); $th = centreon::plugins::misc::expand_exponential(value => $low_th) . ':' if (defined($low_th));
$th .= $high_th if (defined($high_th)); $th .= centreon::plugins::misc::expand_exponential(value => $high_th) if (defined($high_th));
return $th; return $th;
} }

View File

@ -438,6 +438,15 @@ sub convert_bytes {
return $value; return $value;
} }
sub expand_exponential {
my (%options) = @_;
return $options{value} unless ($options{value} =~ /^(.*)e([-+]?)(.*)$/);
my ($num, $sign, $exp) = ($1, $2, $3);
my $sig = $sign eq '-' ? "." . ($exp - 1 + length $num) : '';
return sprintf("%${sig}f", $options{value});
}
sub parse_threshold { sub parse_threshold {
my (%options) = @_; my (%options) = @_;