Fixes wrong conversion of certain threshold values

This commit is contained in:
Lord Hepipud 2022-08-24 09:57:30 +02:00
parent 5d661581e9
commit 116eaa02f3
4 changed files with 6 additions and 5 deletions

View file

@ -1,4 +1,4 @@
<# <#
### Note ### ### Note ###
This file is shipping plain with Icinga for Windows for each version. This file is shipping plain with Icinga for Windows for each version.

View file

@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#476](https://github.com/Icinga/icinga-powershell-framework/pull/476) Fixes exception `You cannot call a method on va null-valued expression` during installation in case no background daemon is configured * [#476](https://github.com/Icinga/icinga-powershell-framework/pull/476) Fixes exception `You cannot call a method on va null-valued expression` during installation in case no background daemon is configured
* [#482](https://github.com/Icinga/icinga-powershell-framework/pull/482) Fixes encoding problems with special chars or German umlauts during plugin execution and unescaped whitespace in plugin argument strings like `Icinga for Windows`, which was previously wrongly rended as `Icinga` for example * [#482](https://github.com/Icinga/icinga-powershell-framework/pull/482) Fixes encoding problems with special chars or German umlauts during plugin execution and unescaped whitespace in plugin argument strings like `Icinga for Windows`, which was previously wrongly rended as `Icinga` for example
* [#489](https://github.com/Icinga/icinga-powershell-framework/issues/489) Fixes error message `This argument does not support the % unit` in case a `BaseValue` is set, but the actual value is `0` * [#489](https://github.com/Icinga/icinga-powershell-framework/issues/489) Fixes error message `This argument does not support the % unit` in case a `BaseValue` is set, but the actual value is `0`
* [#503](https://github.com/Icinga/icinga-powershell-framework/issues/503) Fixes wrong conversion of values for `Convert-IcingaPluginThresholds`, which did not properly handle string values containing certain units inside the string itself
* [#505](https://github.com/Icinga/icinga-powershell-framework/issues/505) Fixes certificate generation and host registration, in case a custom hostname was set during usage of `Install-Icinga` automation * [#505](https://github.com/Icinga/icinga-powershell-framework/issues/505) Fixes certificate generation and host registration, in case a custom hostname was set during usage of `Install-Icinga` automation
* [#529](https://github.com/Icinga/icinga-powershell-framework/pull/529) Fixes package manifest reader for Icinga for Windows components on Windows 2012 R2 and older * [#529](https://github.com/Icinga/icinga-powershell-framework/pull/529) Fixes package manifest reader for Icinga for Windows components on Windows 2012 R2 and older
* [#523](https://github.com/Icinga/icinga-powershell-framework/pull/523) Fixes errors on encapsulated PowerShell calls for missing Cmdlets `Write-IcingaConsoleError` and `Optimize-IcingaForWindowsMemory` * [#523](https://github.com/Icinga/icinga-powershell-framework/pull/523) Fixes errors on encapsulated PowerShell calls for missing Cmdlets `Write-IcingaConsoleError` and `Optimize-IcingaForWindowsMemory`

View file

@ -8,11 +8,11 @@ function Convert-Bytes()
# Ensure we always use proper formatting of values # Ensure we always use proper formatting of values
$Value = $Value.Replace(',', '.'); $Value = $Value.Replace(',', '.');
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) { If (($Value -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) {
$Value = [string]::Format('{0}B', $Value); $Value = [string]::Format('{0}B', $Value);
} }
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) { If (($Value -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
[single]$CurrentValue = $Matches[1]; [single]$CurrentValue = $Matches[1];
[string]$CurrentUnit = $Matches[2]; [string]$CurrentUnit = $Matches[2];

View file

@ -134,14 +134,14 @@ function Convert-IcingaPluginThresholds()
$ThresholdValue = $ThresholdValue.Substring(1, $ThresholdValue.Length - 1); $ThresholdValue = $ThresholdValue.Substring(1, $ThresholdValue.Length - 1);
} }
If (($ThresholdValue -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) { If (($ThresholdValue -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
$WorkUnit = 'B'; $WorkUnit = 'B';
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) { if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force;
} }
$Value = (Convert-Bytes -Value $ThresholdValue -Unit $WorkUnit).Value; $Value = (Convert-Bytes -Value $ThresholdValue -Unit $WorkUnit).Value;
$RetValue.Unit = $WorkUnit; $RetValue.Unit = $WorkUnit;
} elseif (($ThresholdValue -Match "(^[\d\.]*) ?(ms|s|m|h|d|w|M|y)")) { } elseif (($ThresholdValue -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(ms|s|m|h|d|w|M|y)")) {
$WorkUnit = 's'; $WorkUnit = 's';
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) { if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force; Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force;