Fix exception on negative values

This commit is contained in:
Lord Hepipud 2021-07-27 14:56:37 +02:00
parent afb004af03
commit 57e55ecada
2 changed files with 18 additions and 2 deletions

View file

@ -11,7 +11,11 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?closed=1)
## Enhancements
### Bugfixes
* [#311](https://github.com/Icinga/icinga-powershell-framework/issues/311) Fixes an issue with negative inputs on some scenarios which will cause an exception for checks instead of continuing executing them properly
### Enhancements
* [#301](https://github.com/Icinga/icinga-powershell-framework/pull/301) Improves error handling to no longer print passwords in case `String` is used for `SecureString` arguments
* [#305](https://github.com/Icinga/icinga-powershell-framework/pull/305) Adds a new Cmdlet to test if functions with `Add-Type` are already present inside the current scope of the shell

View file

@ -103,6 +103,7 @@ function Convert-IcingaPluginThresholds()
[bool]$HasTilde = $FALSE;
[bool]$HasAt = $FALSE;
[bool]$Negate = $FALSE;
$Value = '';
$WorkUnit = '';
@ -114,6 +115,11 @@ function Convert-IcingaPluginThresholds()
$ThresholdValue = $ThresholdValue.Replace('@', '');
}
if ($ThresholdValue[0] -eq '-' -And $ThresholdValue.Length -ge 1) {
$Negate = $TRUE;
$ThresholdValue = $ThresholdValue.Substring(1, $ThresholdValue.Length - 1);
}
If (($ThresholdValue -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
$WorkUnit = 'B';
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
@ -133,7 +139,7 @@ function Convert-IcingaPluginThresholds()
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
$RetValue.Unit = $WorkUnit;
} else {
# Load all other units/values genericly
# Load all other units/values generically
[string]$StrNumeric = '';
[bool]$FirstChar = $TRUE;
[bool]$Delimiter = $FALSE;
@ -161,6 +167,12 @@ function Convert-IcingaPluginThresholds()
}
}
if ((Test-Numeric $Value) -And $Negate) {
$Value = $Value * -1;
} elseif ($Negate) {
$Value = [string]::Format('-{0}', $Value);
}
if ($HasTilde) {
$ConvertedValue += [string]::Format('~{0}', $Value);
} elseif ($HasAt) {