Merge pull request #257 from Icinga:fix/threshold_conversion_generic_unit_exception

Fix: Unhandled units might cause exception on maximum compare

Unhandled units like `c` are causing exceptions, in case they are used as maximum or base value.
This commit is contained in:
Lord Hepipud 2021-05-28 23:39:03 +02:00 committed by GitHub
commit b6c699f5de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -133,7 +133,28 @@ function Convert-IcingaPluginThresholds()
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
$RetValue.Unit = $WorkUnit;
} else {
$Value = $ThresholdValue;
# Load all other units/values genericly
[string]$StrNumeric = '';
[bool]$FirstChar = $TRUE;
foreach ($entry in ([string]($ThresholdValue)).ToCharArray()) {
if (Test-Numeric $entry) {
$StrNumeric += $entry;
$FirstChar = $FALSE;
} else {
if ([string]::IsNullOrEmpty($RetValue.Unit) -And $FirstChar -eq $FALSE) {
$RetValue.Unit = $entry;
} else {
$StrNumeric = '';
$RetValue.Unit = '';
break;
}
}
}
if ([string]::IsNullOrEmpty($StrNumeric)) {
$Value = $ThresholdValue;
} else {
$Value = [decimal]$StrNumeric;
}
}
if ($HasTilde) {