diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index c16c408..9c9894a 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -22,6 +22,7 @@ This beta release has reworked the entire handling on how thresholds and the che * [#735](https://github.com/Icinga/icinga-powershell-framework/pull/735) Fixes an issue with filter for EventLog events, which did not properly handle multiple event id includes, causing empty results * [#743](https://github.com/Icinga/icinga-powershell-framework/pull/743) In the REST API response header `Server`, tell the software version, not the machine name (RFC 9110) * [#745](https://github.com/Icinga/icinga-powershell-framework/pull/745) Fixes an issue for service provider with service names not interpreted correctly in case it contains `[]` +* [#746](https://github.com/Icinga/icinga-powershell-framework/issues/746) Fixes an issue with performance counters, sometimes reporting empty values instead of at least 0 ### Enhancements diff --git a/lib/core/perfcounter/New-IcingaPerformanceCounterObject.psm1 b/lib/core/perfcounter/New-IcingaPerformanceCounterObject.psm1 index a907b03..f0bdcce 100644 --- a/lib/core/perfcounter/New-IcingaPerformanceCounterObject.psm1 +++ b/lib/core/perfcounter/New-IcingaPerformanceCounterObject.psm1 @@ -82,6 +82,7 @@ function New-IcingaPerformanceCounterObject() # Initialise the counter try { $this.PerfCounter.NextValue() | Out-Null; + $this.PerfCounter.NextSample() | Out-Null; } catch { # Nothing to do here, will be handled later } @@ -110,17 +111,23 @@ function New-IcingaPerformanceCounterObject() $pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value { [hashtable]$CounterData = @{ }; + $CounterValue = $this.PerfCounter.NextValue(); + + if ($null -eq $CounterValue) { + $CounterValue = 0; + } + try { [string]$CounterType = $this.PerfCounter.CounterType; - $CounterData.Add('value', ([math]::Round([decimal]$this.PerfCounter.NextValue(), 6))); + $CounterData.Add('value', ([math]::Round([decimal]$CounterValue, 6))); $CounterData.Add('sample', $this.PerfCounter.NextSample()); $CounterData.Add('help', $this.PerfCounter.CounterHelp); $CounterData.Add('type', $CounterType); $CounterData.Add('error', $null); } catch { $CounterData = @{ }; - $CounterData.Add('value', $null); - $CounterData.Add('sample', $null); + $CounterData.Add('value', 0); # Set the value to 0 in case of an error + $CounterData.Add('sample', 0); $CounterData.Add('help', $null); $CounterData.Add('type', $null); $CounterData.Add('error', $_.Exception.Message); diff --git a/lib/icinga/plugin/New-IcingaCheck.psm1 b/lib/icinga/plugin/New-IcingaCheck.psm1 index 53c24c8..3434a4d 100644 --- a/lib/icinga/plugin/New-IcingaCheck.psm1 +++ b/lib/icinga/plugin/New-IcingaCheck.psm1 @@ -198,7 +198,7 @@ function New-IcingaCheck() [string]$LabelName = (Format-IcingaPerfDataLabel -PerfData $this.Name); [string]$MultiLabelName = (Format-IcingaPerfDataLabel -PerfData $this.Name -MultiOutput); - $value = ConvertTo-Integer -Value $this.__ThresholdObject.Value -NullAsEmpty; + $value = ConvertTo-Integer -Value $this.__ThresholdObject.Value; $warning = ''; $critical = '';