From 03e874c75b4aba7b0690c9a1a2efeed0e64971b0 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 26 Jun 2017 15:52:03 +0200 Subject: [PATCH] add convert misc function --- centreon/plugins/misc.pm | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index e9f7a1eda..6c1fb6525 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -320,14 +320,14 @@ sub trim { } sub powershell_encoded { - my ($value) = $_[0]; + my ($value) = $_[0]; - require Encode; - require MIME::Base64; - my $bytes = Encode::encode("utf16LE", $value); - my $script = MIME::Base64::encode_base64($bytes, "\n"); - $script =~ s/\n//g; - return $script; + require Encode; + require MIME::Base64; + my $bytes = Encode::encode("utf16LE", $value); + my $script = MIME::Base64::encode_base64($bytes, "\n"); + $script =~ s/\n//g; + return $script; } sub powershell_escape { @@ -389,6 +389,19 @@ sub change_seconds { return $str; } +sub convert_bytes { + my (%options) = @_; + my %expo = (k => 1, m => 2, g => 3, t => 4); + my $value = $options{value}; + my $base = defined($options{network}) ? 1000 : 1020; + + if ($options{unit} =~ /([kmgt])b/i) { + $value = $value * ($base ** $expo{lc($1)}); + } + + return $value; +} + 1; __END__