diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 8a54a47..4ddec69 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -14,8 +14,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic ## 1.5.1 (pending) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/17?closed=1) + ### Bugfixes +* [#276](https://github.com/Icinga/icinga-powershell-framework/pull/276) Fixes check value conversion to decimal, which sometimes did not resolve values properly and caused conversion issues * [#282](https://github.com/Icinga/icinga-powershell-framework/issues/282) Fixes issue on `System.Text.StringBuilder` which fails to initialize properly on some older Windows systems ## 1.5.0 (2021-06-02) diff --git a/lib/core/tools/Test-IcingaDecimal.psm1 b/lib/core/tools/Test-IcingaDecimal.psm1 new file mode 100644 index 0000000..c264fa0 --- /dev/null +++ b/lib/core/tools/Test-IcingaDecimal.psm1 @@ -0,0 +1,26 @@ +function Test-IcingaDecimal() +{ + param ( + $Value = $null + ); + + [hashtable]$RetValue = @{ + 'Value' = $Value; + 'Decimal' = $FALSE; + }; + + if ($null -eq $Value -Or [string]::IsNullOrEmpty($Value)) { + return $RetValue; + } + + $TmpValue = ([string]$Value).Replace(',', '.'); + + if ((Test-Numeric $TmpValue) -eq $FALSE) { + return $RetValue; + } + + $RetValue.Value = [decimal]$TmpValue; + $RetValue.Decimal = $TRUE; + + return $RetValue; +} diff --git a/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 b/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 index c169675..d384711 100644 --- a/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 +++ b/lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1 @@ -18,6 +18,17 @@ function Compare-IcingaPluginThresholds() [string]$TimeInterval = $null ); + # Fix possible numeric value comparison issues + $TestInput = Test-IcingaDecimal $InputValue; + $BaseInput = Test-IcingaDecimal $BaseValue; + + if ($TestInput.Decimal) { + [decimal]$InputValue = [decimal]$TestInput.Value; + } + if ($BaseInput.Decimal) { + [decimal]$BaseValue = [decimal]$BaseInput.Value; + } + $IcingaThresholds = New-Object -TypeName PSObject; $IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Value' -Value $InputValue; $IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue; @@ -115,9 +126,10 @@ function Compare-IcingaPluginThresholds() $TempValue = (Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $InputValue, $Unit))); $InputValue = $TempValue.Value; $TmpUnit = $TempValue.Unit; + $TestInput = Test-IcingaDecimal $InputValue; - if (Test-Numeric $InputValue) { - [decimal]$InputValue = [decimal]$InputValue; + if ($TestInput.Decimal) { + [decimal]$InputValue = [decimal]$TestInput.Value; } $IcingaThresholds.RawValue = $InputValue;