Fixes null value exceptions on checks with units

This commit is contained in:
Lord Hepipud 2024-02-12 11:24:51 +01:00
parent 5305f7e14c
commit 96b1389943
2 changed files with 8 additions and 1 deletions

View file

@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#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
* [#678](https://github.com/Icinga/icinga-powershell-framework/pull/678) Fixes various memory leaks in Icinga for Windows API core and check handler
* [#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
## 1.11.1 (2023-11-07)

View file

@ -21,7 +21,13 @@ function New-IcingaCheck()
$IcingaCheck.Name = $Name;
$IcingaCheck.__ObjectType = 'IcingaCheck';
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value $Value;
# Ensure we always set our current value to 0 in case it is null and we set a unit, to prevent conversion exceptions
if ([string]::IsNullOrEmpty($Unit) -eq $FALSE -And $null -eq $Value) {
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value 0;
} else {
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Value' -Value $Value;
}
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'BaseValue' -Value $BaseValue;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'Unit' -Value $Unit;
$IcingaCheck | Add-Member -MemberType NoteProperty -Name 'MetricIndex' -Value $MetricIndex;