From c1f4328b250a582d08dccb599547789bdd72ddd8 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 4 Jun 2020 13:36:31 +0200 Subject: [PATCH] enhance convert_bytes --- centreon/plugins/misc.pm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index d4334ff58..cd1ffb809 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -430,9 +430,15 @@ sub convert_bytes { my (%options) = @_; my %expo = (k => 1, m => 2, g => 3, t => 4, p => 5); - my $value = $options{value}; + my ($value, $unit) = ($options{value}, $options{unit}); + if (defined($options{pattern})) { + return undef if ($value !~ /$options{pattern}/); + $value = $1; + $unit = $2; + } + my $base = defined($options{network}) ? 1000 : 1024; - if ($options{unit} =~ /([kmgt])b/i) { + if ($unit =~ /([kmgtp])i?b/i) { $value = $value * ($base ** $expo{lc($1)}); }