Skip to content

Commit 88ee35d

Browse files
authored
Merge pull request #747 from Icinga:fix/performance_counter_null_values
Fix: Performance counter results sometimes reporting null instead of 0 Fixes an issue with performance counters, sometimes reporting empty values instead of at least 0
2 parents 6b45918 + c70da2a commit 88ee35d

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This beta release has reworked the entire handling on how thresholds and the che
2222
* [#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
2323
* [#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)
2424
* [#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 `[]`
25+
* [#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
2526

2627
### Enhancements
2728

lib/core/perfcounter/New-IcingaPerformanceCounterObject.psm1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function New-IcingaPerformanceCounterObject()
8282
# Initialise the counter
8383
try {
8484
$this.PerfCounter.NextValue() | Out-Null;
85+
$this.PerfCounter.NextSample() | Out-Null;
8586
} catch {
8687
# Nothing to do here, will be handled later
8788
}
@@ -110,17 +111,23 @@ function New-IcingaPerformanceCounterObject()
110111
$pc_instance | Add-Member -MemberType ScriptMethod -Name 'Value' -Value {
111112
[hashtable]$CounterData = @{ };
112113

114+
$CounterValue = $this.PerfCounter.NextValue();
115+
116+
if ($null -eq $CounterValue) {
117+
$CounterValue = 0;
118+
}
119+
113120
try {
114121
[string]$CounterType = $this.PerfCounter.CounterType;
115-
$CounterData.Add('value', ([math]::Round([decimal]$this.PerfCounter.NextValue(), 6)));
122+
$CounterData.Add('value', ([math]::Round([decimal]$CounterValue, 6)));
116123
$CounterData.Add('sample', $this.PerfCounter.NextSample());
117124
$CounterData.Add('help', $this.PerfCounter.CounterHelp);
118125
$CounterData.Add('type', $CounterType);
119126
$CounterData.Add('error', $null);
120127
} catch {
121128
$CounterData = @{ };
122-
$CounterData.Add('value', $null);
123-
$CounterData.Add('sample', $null);
129+
$CounterData.Add('value', 0); # Set the value to 0 in case of an error
130+
$CounterData.Add('sample', 0);
124131
$CounterData.Add('help', $null);
125132
$CounterData.Add('type', $null);
126133
$CounterData.Add('error', $_.Exception.Message);

lib/icinga/plugin/New-IcingaCheck.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function New-IcingaCheck()
198198

199199
[string]$LabelName = (Format-IcingaPerfDataLabel -PerfData $this.Name);
200200
[string]$MultiLabelName = (Format-IcingaPerfDataLabel -PerfData $this.Name -MultiOutput);
201-
$value = ConvertTo-Integer -Value $this.__ThresholdObject.Value -NullAsEmpty;
201+
$value = ConvertTo-Integer -Value $this.__ThresholdObject.Value;
202202
$warning = '';
203203
$critical = '';
204204

0 commit comments

Comments
 (0)