mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Fixes input value decimal conversion
This commit is contained in:
parent
d9a66f0f94
commit
0ca98758fc
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)
|
||||
|
||||
[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)
|
||||
|
|
|
|||
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
|
||||
);
|
||||
|
||||
# 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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue