From 6b3f27fae1f95da14144103aa0c97f2be13cb960 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Fri, 28 May 2021 23:36:57 +0200 Subject: [PATCH] Fixes unhandled units might cause exception --- .../tools/Convert-IcingaPluginThresholds.psm1 | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/core/tools/Convert-IcingaPluginThresholds.psm1 b/lib/core/tools/Convert-IcingaPluginThresholds.psm1 index 9790f78..faedd4b 100644 --- a/lib/core/tools/Convert-IcingaPluginThresholds.psm1 +++ b/lib/core/tools/Convert-IcingaPluginThresholds.psm1 @@ -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) {