Skip to content

Commit e670cc3

Browse files
committed
Fixes null value exceptions on checks with units
1 parent 5305f7e commit e670cc3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1919

2020
* [#673](https://github.com/Icinga/icinga-powershell-framework/pull/673) Fixes a memory leak while fetching Windows EventLog information by using CLI tools and inside the Hyper-V provide
2121
* [#678](https://github.com/Icinga/icinga-powershell-framework/pull/678) Fixes various memory leaks in Icinga for Windows API core and check handler
22+
* [#680](https://github.com/Icinga/icinga-powershell-framework/pull/680) Fixes exception in some cases, when provider or metrics return values as `null` instead of `0` while units are being used for check objects.
2223

2324
## 1.11.1 (2023-11-07)
2425

lib/icinga/plugin/New-IcingaCheck.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ function New-IcingaCheck()
2121
$IcingaCheck.Name = $Name;
2222
$IcingaCheck.__ObjectType = 'IcingaCheck';
2323

24-
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value $Value;
24+
# Ensure we always set our current value to 0 in case it is null and we set a unit, to prevent conversion exceptions
25+
if ([string]::IsNullOrEmpty($Unit) -eq $FALSE -And $null -eq $Value) {
26+
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value 0;
27+
} else {
28+
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value $Value;
29+
}
30+
2531
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue;
2632
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Unit' -Value $Unit;
2733
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'MetricIndex' -Value $MetricIndex;

0 commit comments

Comments
 (0)