Skip to content

Commit c8dacba

Browse files
authored
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.
2 parents afb004a + 57e55ec commit c8dacba

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

doc/31-Changelog.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1111

1212
[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/15?closed=1)
1313

14-
## Enhancements
14+
### Bugfixes
15+
16+
* [#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
17+
18+
### Enhancements
1519

1620
* [#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
1721
* [#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

lib/core/tools/Convert-IcingaPluginThresholds.psm1

+13-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function Convert-IcingaPluginThresholds()
103103

104104
[bool]$HasTilde = $FALSE;
105105
[bool]$HasAt = $FALSE;
106+
[bool]$Negate = $FALSE;
106107
$Value = '';
107108
$WorkUnit = '';
108109

@@ -114,6 +115,11 @@ function Convert-IcingaPluginThresholds()
114115
$ThresholdValue = $ThresholdValue.Replace('@', '');
115116
}
116117

118+
if ($ThresholdValue[0] -eq '-' -And $ThresholdValue.Length -ge 1) {
119+
$Negate = $TRUE;
120+
$ThresholdValue = $ThresholdValue.Substring(1, $ThresholdValue.Length - 1);
121+
}
122+
117123
If (($ThresholdValue -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
118124
$WorkUnit = 'B';
119125
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
@@ -133,7 +139,7 @@ function Convert-IcingaPluginThresholds()
133139
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
134140
$RetValue.Unit = $WorkUnit;
135141
} else {
136-
# Load all other units/values genericly
142+
# Load all other units/values generically
137143
[string]$StrNumeric = '';
138144
[bool]$FirstChar = $TRUE;
139145
[bool]$Delimiter = $FALSE;
@@ -161,6 +167,12 @@ function Convert-IcingaPluginThresholds()
161167
}
162168
}
163169

170+
if ((Test-Numeric $Value) -And $Negate) {
171+
$Value = $Value * -1;
172+
} elseif ($Negate) {
173+
$Value = [string]::Format('-{0}', $Value);
174+
}
175+
164176
if ($HasTilde) {
165177
$ConvertedValue += [string]::Format('~{0}', $Value);
166178
} elseif ($HasAt) {

0 commit comments

Comments
 (0)