Merge pull request #680 from Icinga:fix/null_value_on_unit_checks

Fix: Null value exceptions on checks with units

Fixes exception in some cases, when provider or metrics return values as `null` instead of `0` while units are being used for check objects.

This affects the Process plugin as one example
This commit is contained in:
Lord Hepipud 2024-02-12 11:28:43 +01:00 committed by GitHub
commit 615849d0e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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;