Fixes unhandled units might cause exception

This commit is contained in:
Lord Hepipud 2021-05-28 23:36:57 +02:00
parent 72c1495165
commit 6b3f27fae1

View file

@ -133,7 +133,28 @@ function Convert-IcingaPluginThresholds()
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', ''); $Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
$RetValue.Unit = $WorkUnit; $RetValue.Unit = $WorkUnit;
} else { } 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) { if ($HasTilde) {