mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Merge pull request #277 from Icinga:fix/input_conversion_decimal
Fix: Input value decimal conversion Fixes check value conversion to decimal, which sometimes did not resolve values properly and caused conversion issues
This commit is contained in:
commit
375a4e70cf
3 changed files with 42 additions and 2 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
26
lib/core/tools/Test-IcingaDecimal.psm1
Normal file
26
lib/core/tools/Test-IcingaDecimal.psm1
Normal 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;
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue