diff --git a/lib/core/tools/Convert-Bytes.psm1 b/lib/core/tools/Convert-Bytes.psm1 index b2e484a..0ab5a5e 100644 --- a/lib/core/tools/Convert-Bytes.psm1 +++ b/lib/core/tools/Convert-Bytes.psm1 @@ -5,12 +5,12 @@ function Convert-Bytes() [string]$Unit ); - If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|Kibi|Mibi|Gibi|Tibi|Pibi)")) { + If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) { [single]$CurrentValue = $Matches[1]; [string]$CurrentUnit = $Matches[2]; switch ($CurrentUnit) { - { 'KiBi', 'Mibi', 'Gibi', 'Tibi', 'Pibi' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;} + { 'KiB', 'MiB', 'GiB', 'TiB', 'PiB' -contains $_} { $CurrentValue = ConvertTo-ByteIEC $CurrentValue $CurrentUnit; $boolOption = $true;} { 'KB', 'MB', 'GB', 'TB', 'PB' -contains $_} { $CurrentValue = ConvertTo-ByteSI $CurrentValue $CurrentUnit; $boolOption = $true;} } @@ -22,11 +22,11 @@ function Convert-Bytes() { 'GB' -contains $_} { $FinalValue = ConvertTo-GigaByte $CurrentValue -Unit B; $boolOption = $true;} { 'TB' -contains $_} { $FinalValue = ConvertTo-TeraByte $CurrentValue -Unit B; $boolOption = $true;} { 'PT' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Kibi' -contains $_} { $FinalValue = ConvertTo-KibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Mibi' -contains $_} { $FinalValue = ConvertTo-MibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Gibi' -contains $_} { $FinalValue = ConvertTo-GibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Tibi' -contains $_} { $FinalValue = ConvertTo-TibiByte $CurrentValue -Unit B; $boolOption = $true;} - { 'Piti' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} + { 'KiB' -contains $_} { $FinalValue = ConvertTo-KiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'MiB' -contains $_} { $FinalValue = ConvertTo-MiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'GiB' -contains $_} { $FinalValue = ConvertTo-GiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'TiB' -contains $_} { $FinalValue = ConvertTo-TiBByte $CurrentValue -Unit B; $boolOption = $true;} + { 'PiB' -contains $_} { $FinalValue = ConvertTo-PetaByte $CurrentValue -Unit B; $boolOption = $true;} default { if (-Not $boolOption) { diff --git a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 index d1ac06b..fa8f4d3 100644 --- a/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 +++ b/lib/core/tools/ConvertTo-ByteUnitIEC.psm1 @@ -7,11 +7,11 @@ function ConvertTo-ByteIEC() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 50)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -22,7 +22,7 @@ function ConvertTo-ByteIEC() return $result; } -function ConvertTo-KibiByte() +function ConvertTo-KiBByte() { param( [single]$Value, @@ -31,11 +31,11 @@ function ConvertTo-KibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 40)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -46,7 +46,7 @@ function ConvertTo-KibiByte() return $result; } -function ConvertTo-MibiByte() +function ConvertTo-MiBByte() { param( [single]$Value, @@ -55,11 +55,11 @@ function ConvertTo-MibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 30)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -70,7 +70,7 @@ function ConvertTo-MibiByte() return $result; } -function ConvertTo-GibiByte() +function ConvertTo-GiBByte() { param( [single]$Value, @@ -79,11 +79,11 @@ function ConvertTo-GibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 20)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -94,7 +94,7 @@ function ConvertTo-GibiByte() return $result; } -function ConvertTo-TibiByte() +function ConvertTo-TiBByte() { param( [single]$Value, @@ -103,11 +103,11 @@ function ConvertTo-TibiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = $Value; $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = ($Value * [math]::Pow(2, 10)); $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; @@ -118,7 +118,7 @@ function ConvertTo-TibiByte() return $result; } -function ConvertTo-PitiByte() +function ConvertTo-PiBByte() { param( [single]$Value, @@ -127,11 +127,11 @@ function ConvertTo-PitiByte() switch ($Unit) { { 'B', 'Byte' -contains $_ } { $result = ($Value / [math]::Pow(2, 50)); $boolOption = $true; } - { 'Kibi', 'KibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } - { 'Mibi', 'MibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } - { 'Gibi', 'GibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } - { 'Tibi', 'TibiByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } - { 'Piti', 'PitiByte' -contains $_ } { $result = $Value; $boolOption = $true; } + { 'KiB', 'KiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 40)); $boolOption = $true; } + { 'MiB', 'Mebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 30)); $boolOption = $true; } + { 'GiB', 'GiBByte' -contains $_ } { $result = ($Value / [math]::Pow(2, 20)); $boolOption = $true; } + { 'TiB', 'Tebibyte' -contains $_ } { $result = ($Value / [math]::Pow(2, 10)); $boolOption = $true; } + { 'PiB', 'Pebibyte' -contains $_ } { $result = $Value; $boolOption = $true; } default { if (-Not $boolOption) { Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.ConversionUnitMissing -Force; diff --git a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 index 18c80ed..d4dfded 100644 --- a/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 +++ b/lib/icinga/exception/Icinga_IcingaExceptionEnums.psm1 @@ -13,7 +13,7 @@ PerformanceCounter = 'A plugin failed to fetch Performance Counter information. Please ensure the counter is written properly and available on your system.'; EventLogLogName = 'Failed to fetch EventLog information. Please specify a valid LogName.'; EventLog = 'Failed to fetch EventLog information. Please check your inputs for EntryTypes and other categories and try again.'; - ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, Kibi, Mibi, Gibi, Tibi, Piti".'; + ConversionUnitMissing = 'Unable to parse input value. You have to add an unit to your input value. Example: "10GB". Allowed units are: "B, KB, MB, GB, TB, PT, KiB, MiB, GiB, TiB, PiB".'; }; <#