Skip to content

Commit 786fa9f

Browse files
authored
Merge pull request #555 from Icinga:fix/plugin_thresholds_invalid_conversion
Fix: Wrong conversion of certain threshold values Fixes wrong conversion of values for `Convert-IcingaPluginThresholds`, which did not properly handle string values containing certain units inside the string itself
2 parents 95be598 + 116eaa0 commit 786fa9f

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

cache/framework_cache.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<#
1+
<#
22
### Note ###
33
44
This file is shipping plain with Icinga for Windows for each version.

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1717
* [#476](https://github.com/Icinga/icinga-powershell-framework/pull/476) Fixes exception `You cannot call a method on va null-valued expression` during installation in case no background daemon is configured
1818
* [#482](https://github.com/Icinga/icinga-powershell-framework/pull/482) Fixes encoding problems with special chars or German umlauts during plugin execution and unescaped whitespace in plugin argument strings like `Icinga for Windows`, which was previously wrongly rended as `Icinga` for example
1919
* [#489](https://github.com/Icinga/icinga-powershell-framework/issues/489) Fixes error message `This argument does not support the % unit` in case a `BaseValue` is set, but the actual value is `0`
20+
* [#503](https://github.com/Icinga/icinga-powershell-framework/issues/503) Fixes wrong conversion of values for `Convert-IcingaPluginThresholds`, which did not properly handle string values containing certain units inside the string itself
2021
* [#505](https://github.com/Icinga/icinga-powershell-framework/issues/505) Fixes certificate generation and host registration, in case a custom hostname was set during usage of `Install-Icinga` automation
2122
* [#529](https://github.com/Icinga/icinga-powershell-framework/pull/529) Fixes package manifest reader for Icinga for Windows components on Windows 2012 R2 and older
2223
* [#523](https://github.com/Icinga/icinga-powershell-framework/pull/523) Fixes errors on encapsulated PowerShell calls for missing Cmdlets `Write-IcingaConsoleError` and `Optimize-IcingaForWindowsMemory`

lib/core/tools/Convert-Bytes.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ function Convert-Bytes()
88
# Ensure we always use proper formatting of values
99
$Value = $Value.Replace(',', '.');
1010

11-
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) {
11+
If (($Value -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)") -eq $FALSE) {
1212
$Value = [string]::Format('{0}B', $Value);
1313
}
1414

15-
If (($Value -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
15+
If (($Value -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
1616
[single]$CurrentValue = $Matches[1];
1717
[string]$CurrentUnit = $Matches[2];
1818

lib/core/tools/Convert-IcingaPluginThresholds.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ function Convert-IcingaPluginThresholds()
134134
$ThresholdValue = $ThresholdValue.Substring(1, $ThresholdValue.Length - 1);
135135
}
136136

137-
If (($ThresholdValue -Match "(^[\d\.]*) ?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
137+
If (($ThresholdValue -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(B|KB|MB|GB|TB|PT|KiB|MiB|GiB|TiB|PiB)")) {
138138
$WorkUnit = 'B';
139139
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
140140
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force;
141141
}
142142
$Value = (Convert-Bytes -Value $ThresholdValue -Unit $WorkUnit).Value;
143143
$RetValue.Unit = $WorkUnit;
144-
} elseif (($ThresholdValue -Match "(^[\d\.]*) ?(ms|s|m|h|d|w|M|y)")) {
144+
} elseif (($ThresholdValue -Match "(^-?[0-9].*)+((\.|\,)+[0-9])?(ms|s|m|h|d|w|M|y)")) {
145145
$WorkUnit = 's';
146146
if ([string]::IsNullOrEmpty($RetValue.Unit) -eq $FALSE -And $RetValue.Unit -ne $WorkUnit) {
147147
Exit-IcingaThrowException -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.MultipleUnitUsage -Force;

0 commit comments

Comments
 (0)