Skip to content

Commit 0893325

Browse files
authored
Merge pull request #208 from Icinga:fix/fix_generic_plugin_threshold_conversion
Fix: Plugin threshold conversion and adds % unit handling Fixes `Convert-IcingaPluginThresholds` which sometimes did not return proper numeric usable values for our internal functions, causing issues on plugin calls. In addition the function now also supports the handling for % units.
2 parents 6f89f19 + e7c33d2 commit 0893325

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2323
### Bugfixes
2424

2525
* [#206](https://github.com/Icinga/icinga-powershell-framework/pull/206) Fixes background service check daemon for collecting metrics over time which will no longer share data between configured checks which might cause higher CPU load and a possible memory leak
26+
* [#208](https://github.com/Icinga/icinga-powershell-framework/pull/208) Fixes `Convert-IcingaPluginThresholds` which sometimes did not return proper numeric usable values for our internal functions, causing issues on plugin calls. In addition the function now also supports the handling for % units.
2627

2728
## 1.3.1 (2021-02-04)
2829

lib/core/tools/Convert-IcingaPluginThresholds.psm1

+8-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function Convert-IcingaPluginThresholds()
9090
$Threshold = $Threshold.Replace(',', '.');
9191

9292
[array]$Content = @();
93-
93+
9494
if ($Threshold.Contains(':')) {
9595
$Content = $Threshold.Split(':');
9696
} else {
@@ -128,6 +128,10 @@ function Convert-IcingaPluginThresholds()
128128
}
129129
$Value = (ConvertTo-Seconds -Value $ThresholdValue);
130130
$RetValue.Unit = $WorkUnit;
131+
} elseif (($ThresholdValue -Match "(^[\d\.]*) ?(%)")) {
132+
$WorkUnit = '%';
133+
$Value = ([string]$ThresholdValue).Replace(' ', '').Replace('%', '');
134+
$RetValue.Unit = $WorkUnit;
131135
} else {
132136
$Value = $ThresholdValue;
133137
}
@@ -145,11 +149,13 @@ function Convert-IcingaPluginThresholds()
145149

146150
if ([string]::IsNullOrEmpty($Value) -eq $FALSE -And $Value.Contains(':') -eq $FALSE) {
147151
if ((Test-Numeric $Value)) {
148-
$RetValue.Value = [convert]::ToDecimal($Value);
152+
$RetValue.Value = $Value;
149153
return $RetValue;
150154
}
151155
}
152156

157+
# Always ensure we are using correct digits
158+
$Value = ([string]$Value).Replace(',', '.');
153159
$RetValue.Value = $Value;
154160

155161
return $RetValue;

0 commit comments

Comments
 (0)