Skip to content

Commit

Permalink
Fixes input value decimal conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Jun 3, 2021
1 parent 56ac5f9 commit b54968c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ documentation before upgrading to a new release.

Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed).

## 1.6.0 (pending)

[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?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

## 1.5.0 (2021-06-02)

[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/13?closed=1)
Expand Down
26 changes: 26 additions & 0 deletions lib/core/tools/Test-IcingaDecimal.psm1
Original file line number Diff line number Diff line change
@@ -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;
}
16 changes: 14 additions & 2 deletions lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b54968c

Please sign in to comment.