Skip to content

Commit f35a85a

Browse files
committed
Fixes input value conversion for New-IcingaCheck to properly handling different unit types
1 parent b35f0a7 commit f35a85a

4 files changed

Lines changed: 41 additions & 17 deletions

File tree

doc/100-General/10-Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1111

1212
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/38)
1313

14+
## 1.13.3 (tbd)
15+
16+
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/39)
17+
1418
### Bugfixes
1519

1620
* [#787](https://github.com/Icinga/icinga-powershell-framework/pull/787) Fixes the return value in case the `Agent` component could not be installed from `$FALSE` to `null`
21+
* [#796](https://github.com/Icinga/icinga-powershell-framework/issues/796) [#798](https://github.com/Icinga/icinga-powershell-framework/issues/798) Fixes an issue with the new check handling, which did not properly convert values from checks to the correct performance data values and base values in some cases
1722

1823
## 1.13.2 (2025-02-03)
1924

lib/icinga/plugin/Compare-IcingaPluginThresholds.psm1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ function Compare-IcingaPluginThresholds()
126126
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Minimum' -Value (Convert-IcingaPluginThresholds -Threshold $Minium);
127127
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Maximum' -Value (Convert-IcingaPluginThresholds -Threshold $Maximum);
128128

129+
if ($TestInput.Decimal) {
130+
$ConvertedValue = Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $InputValue, $Unit));
131+
132+
if ((Test-IcingaDecimal -Value $ConvertedValue.Value).Decimal) {
133+
$InputValue = [decimal]$ConvertedValue.Value;
134+
$IcingaThresholds.Value = [decimal]$ConvertedValue.Value;
135+
$IcingaThresholds.Unit = $ConvertedValue.Unit;
136+
}
137+
}
138+
139+
if ($BaseInput.Decimal) {
140+
$ConvertedBaseValue = Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $BaseValue, $Unit));
141+
142+
if ((Test-IcingaDecimal -Value $ConvertedBaseValue.Value).Decimal) {
143+
$BaseValue = [decimal]$ConvertedBaseValue.Value;
144+
}
145+
}
146+
129147
# In case we are using % values, we should set the BaseValue always to 100
130148
if ($Unit -eq '%' -And $null -eq $BaseValue) {
131149
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value 100;
@@ -136,17 +154,17 @@ function Compare-IcingaPluginThresholds()
136154
$CheckResult = $null;
137155

138156
if ($Matches) {
139-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.Matches -MetricsOverTime $MoTData;
157+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.Matches -MetricsOverTime $MoTData;
140158
} elseif ($NotMatches) {
141-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.NotMatches -MetricsOverTime $MoTData;
159+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.NotMatches -MetricsOverTime $MoTData;
142160
} elseif ($IsBetween) {
143-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.Between -MetricsOverTime $MoTData;
161+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.Between -MetricsOverTime $MoTData;
144162
} elseif ($IsLowerEqual) {
145-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.LowerEqual -MetricsOverTime $MoTData;
163+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.LowerEqual -MetricsOverTime $MoTData;
146164
} elseif ($IsGreaterEqual) {
147-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.GreaterEqual -MetricsOverTime $MoTData;
165+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -OverrideMode $IcingaEnums.IcingaThresholdMethod.GreaterEqual -MetricsOverTime $MoTData;
148166
} else {
149-
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $Unit -Translation $Translation -MetricsOverTime $MoTData;
167+
$CheckResult = Compare-IcingaPluginValueToThreshold -Value $InputValue -BaseValue $IcingaThresholds.BaseValue -Threshold $IcingaThresholds.Threshold -Unit $IcingaThresholds.Unit -CheckUnit $Unit -Translation $Translation -MetricsOverTime $MoTData;
150168
}
151169

152170
$IcingaThresholds.Message = $CheckResult.Message;

lib/icinga/plugin/Compare-IcingaPluginValueToThreshold.psm1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function Compare-IcingaPluginValueToThreshold()
5757
$Value = $null,
5858
$BaseValue = $null,
5959
$Unit = $null,
60+
$CheckUnit = $null,
6061
$Translation = $null,
6162
$Threshold = $null,
6263
$OverrideMode = $null,
@@ -94,7 +95,7 @@ function Compare-IcingaPluginValueToThreshold()
9495

9596
# Otherwise just convert the values to human readble values
9697
$HumanReadableValue = ConvertTo-IcingaPluginOutputTranslation -Translation $Translation -Value $HumanReadableValue;
97-
$HumanReadableValue = Convert-IcingaPluginValueToString -Value $HumanReadableValue -Unit $Unit;
98+
$HumanReadableValue = Convert-IcingaPluginValueToString -Value $HumanReadableValue -Unit $Unit -OriginalUnit $CheckUnit;
9899

99100
if ($null -eq $Value -Or $null -eq $Threshold -Or [string]::IsNullOrEmpty($Threshold.Raw)) {
100101
$RetValue.Message = $HumanReadableValue;
@@ -139,50 +140,50 @@ function Compare-IcingaPluginValueToThreshold()
139140
}
140141

141142
if ($Value -gt $Threshold.Value) {
142-
$RetValue.Message = [string]::Format('Value {0} is greater than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
143+
$RetValue.Message = [string]::Format('Value {0} is greater than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
143144
return $RetValue;
144145
}
145146
}
146147
break;
147148
};
148149
$IcingaEnums.IcingaThresholdMethod.Lower {
149150
if ($Value -lt $Threshold.Value) {
150-
$RetValue.Message = [string]::Format('Value {0} is lower than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
151+
$RetValue.Message = [string]::Format('Value {0} is lower than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
151152
return $RetValue;
152153
}
153154
break;
154155
};
155156
$IcingaEnums.IcingaThresholdMethod.LowerEqual {
156157
if ($Value -le $Threshold.Value) {
157-
$RetValue.Message = [string]::Format('Value {0} is lower or equal than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
158+
$RetValue.Message = [string]::Format('Value {0} is lower or equal than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
158159
return $RetValue;
159160
}
160161
break;
161162
};
162163
$IcingaEnums.IcingaThresholdMethod.Greater {
163164
if ($Value -gt $Threshold.Value) {
164-
$RetValue.Message = [string]::Format('Value {0} is greater than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
165+
$RetValue.Message = [string]::Format('Value {0} is greater than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
165166
return $RetValue;
166167
}
167168
break;
168169
};
169170
$IcingaEnums.IcingaThresholdMethod.GreaterEqual {
170171
if ($Value -gt $Threshold.Value) {
171-
$RetValue.Message = [string]::Format('Value {0} is greater or equal than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
172+
$RetValue.Message = [string]::Format('Value {0} is greater or equal than threshold {1}{2}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.Value -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
172173
return $RetValue;
173174
}
174175
break;
175176
};
176177
$IcingaEnums.IcingaThresholdMethod.Between {
177178
if ($Value -lt $Threshold.StartRange -Or $Value -gt $Threshold.EndRange) {
178-
$RetValue.Message = [string]::Format('Value {0} is not between thresholds <{1} or >{2}{3}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.StartRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), (Convert-IcingaPluginValueToString -Value $Threshold.EndRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
179+
$RetValue.Message = [string]::Format('Value {0} is not between thresholds <{1} or >{2}{3}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.StartRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), (Convert-IcingaPluginValueToString -Value $Threshold.EndRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
179180
return $RetValue;
180181
}
181182
break;
182183
};
183184
$IcingaEnums.IcingaThresholdMethod.Outside {
184185
if ($Value -ge $Threshold.StartRange -And $Value -le $Threshold.EndRange) {
185-
$RetValue.Message = [string]::Format('Value {0} is between thresholds >={1} and <={2}{3}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.StartRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), (Convert-IcingaPluginValueToString -Value $Threshold.EndRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
186+
$RetValue.Message = [string]::Format('Value {0} is between thresholds >={1} and <={2}{3}', $HumanReadableValue, (Convert-IcingaPluginValueToString -Value $Threshold.StartRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $CheckUnit -UsePercent:$UsePercent -IsThreshold), (Convert-IcingaPluginValueToString -Value $Threshold.EndRange -BaseValue $BaseValue -Unit $Threshold.Unit -OriginalUnit $Unit -UsePercent:$UsePercent -IsThreshold), $MoTMessage);
186187
return $RetValue;
187188
}
188189
break;

lib/icinga/plugin/New-IcingaCheck.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ function New-IcingaCheck()
258258

259259
[string]$PerfDataLabel = [string]::Format(
260260
'{0}={1}{2};{3};{4};{5};{6}',
261-
$PerfDataName,
261+
$PerfDataName.ToLower(),
262262
(Format-IcingaPerfDataValue $value),
263-
$this.__ThresholdObject.PerfUnit,
263+
$this.__ThresholdObject.Unit,
264264
(Format-IcingaPerfDataValue $warning),
265265
(Format-IcingaPerfDataValue $critical),
266266
(Format-IcingaPerfDataValue $this.Minimum),
@@ -289,7 +289,7 @@ function New-IcingaCheck()
289289
}
290290
}
291291

292-
$Global:Icinga.Private.Scheduler.PerfDataWriter.Storage.Append($PerfDataLabel.ToLower()) | Out-Null;
292+
$Global:Icinga.Private.Scheduler.PerfDataWriter.Storage.Append($PerfDataLabel) | Out-Null;
293293
}
294294

295295
$IcingaCheck | Add-Member -MemberType ScriptMethod -Name '__ValidateObject' -Value {

0 commit comments

Comments
 (0)