Fixes input value decimal conversion

This commit is contained in:
Lord Hepipud 2021-06-03 14:27:03 +02:00
parent d9a66f0f94
commit 0ca98758fc
3 changed files with 42 additions and 2 deletions

View file

@ -14,8 +14,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
## 1.5.1 (pending) ## 1.5.1 (pending)
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/17?closed=1) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/17?closed=1)
### Bugfixes ### 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 * [#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) ## 1.5.0 (2021-06-02)

View file

@ -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;
}

View file

@ -18,6 +18,17 @@ function Compare-IcingaPluginThresholds()
[string]$TimeInterval = $null [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 = New-Object -TypeName PSObject;
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Value' -Value $InputValue; $IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Value' -Value $InputValue;
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue; $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))); $TempValue = (Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $InputValue, $Unit)));
$InputValue = $TempValue.Value; $InputValue = $TempValue.Value;
$TmpUnit = $TempValue.Unit; $TmpUnit = $TempValue.Unit;
$TestInput = Test-IcingaDecimal $InputValue;
if (Test-Numeric $InputValue) { if ($TestInput.Decimal) {
[decimal]$InputValue = [decimal]$InputValue; [decimal]$InputValue = [decimal]$TestInput.Value;
} }
$IcingaThresholds.RawValue = $InputValue; $IcingaThresholds.RawValue = $InputValue;