mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #312 from Icinga:fix/negative_values_cause_exception
Fix: Exception on negative offsets In case negative offsets were processed by the checker handling, in some scenarios this would cause an exception.
This commit is contained in:
commit
c8dacba9c5
2 changed files with 18 additions and 2 deletions
|
|
@ -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)
|
[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
|
* [#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
|
* [#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
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,7 @@ function Convert-IcingaPluginThresholds()
|
||||||
|
|
||||||
[bool]$HasTilde = $FALSE;
|
[bool]$HasTilde = $FALSE;
|
||||||
[bool]$HasAt = $FALSE;
|
[bool]$HasAt = $FALSE;
|
||||||
|
[bool]$Negate = $FALSE;
|
||||||
$Value = '';
|
$Value = '';
|
||||||
$WorkUnit = '';
|
$WorkUnit = '';
|
||||||
|
|
||||||
|
|
@ -114,6 +115,11 @@ function Convert-IcingaPluginThresholds()
|
||||||
$ThresholdValue = $ThresholdValue.Replace('@', '');
|
$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)")) {
|
If (($ThresholdValue -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
|
||||||
$WorkUnit = 'B';
|
$WorkUnit = 'B';
|
||||||
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
|
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
|
||||||
|
|
@ -133,7 +139,7 @@ function Convert-IcingaPluginThresholds()
|
||||||
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
|
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
|
||||||
$RetValue.Unit = $WorkUnit;
|
$RetValue.Unit = $WorkUnit;
|
||||||
} else {
|
} else {
|
||||||
# Load all other units/values genericly
|
# Load all other units/values generically
|
||||||
[string]$StrNumeric = '';
|
[string]$StrNumeric = '';
|
||||||
[bool]$FirstChar = $TRUE;
|
[bool]$FirstChar = $TRUE;
|
||||||
[bool]$Delimiter = $FALSE;
|
[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) {
|
if ($HasTilde) {
|
||||||
$ConvertedValue += [string]::Format('~{0}', $Value);
|
$ConvertedValue += [string]::Format('~{0}', $Value);
|
||||||
} elseif ($HasAt) {
|
} elseif ($HasAt) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue