Merge pull request #260 from Icinga:fix/numeric_conversion_for_comparison

Fix: Numeric converison to comparing thresholds is incorrect

Fixes values to be transformed properly to `decimal` to compare them against thresholds provided
This commit is contained in:
Lord Hepipud 2021-05-29 10:57:54 +02:00 committed by GitHub
commit 0a28e25ab0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -170,7 +170,7 @@ function Convert-IcingaPluginThresholds()
if ([string]::IsNullOrEmpty($Value) -eq $FALSE -And $Value.Contains(':') -eq $FALSE) { if ([string]::IsNullOrEmpty($Value) -eq $FALSE -And $Value.Contains(':') -eq $FALSE) {
if ((Test-Numeric $Value)) { if ((Test-Numeric $Value)) {
$RetValue.Value = $Value; $RetValue.Value = [decimal]$Value;
return $RetValue; return $RetValue;
} }
} }

View file

@ -255,9 +255,11 @@ function Compare-IcingaPluginThresholds()
if ((Test-Numeric ($rangeMin.Replace('@', '').Replace('~', '')))) { if ((Test-Numeric ($rangeMin.Replace('@', '').Replace('~', '')))) {
$IcingaThresholds.MinRangeValue = [decimal]($rangeMin.Replace('@', '').Replace('~', '')); $IcingaThresholds.MinRangeValue = [decimal]($rangeMin.Replace('@', '').Replace('~', ''));
[decimal]$rangeMin = [decimal]$rangeMin;
} }
if ((Test-Numeric $rangeMax)) { if ((Test-Numeric $rangeMax)) {
$IcingaThresholds.MaxRangeValue = [decimal]$rangeMax; $IcingaThresholds.MaxRangeValue = [decimal]$rangeMax;
[decimal]$rangeMax = [decimal]$rangeMax;
} }
if ($IsNegating -eq $FALSE -And (Test-Numeric $rangeMin) -And (Test-Numeric $rangeMax)) { if ($IsNegating -eq $FALSE -And (Test-Numeric $rangeMin) -And (Test-Numeric $rangeMax)) {