Skip to content

Commit df37c12

Browse files
authored
Merge pull request #352 from Icinga:feature/summarize_performance_counter_errors
Feature: Adds support to summarize perf counter errors for all failed instances Adds feature to `Invoke-IcingaCheckPerfCounter` to summarize an entire performance counter category, in case all instances of the check fail to prevent large outputs being written into the database ```powershell Invoke-IcingaCheckPerfCounter -PerfCounter '\processor(*)\% processor time'; [UNKNOWN] Performance Counter [UNKNOWN] \processor(*)\% processor time \_ [UNKNOWN] \processor(*)\% processor time \_ [UNKNOWN] Internal Counter Error: Failed to fetch all instances and objects for this performance counter. First error message: Example error message ```
2 parents 8b21639 + a6622d3 commit df37c12

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

doc/31-Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818

1919
* [#332](https://github.com/Icinga/icinga-powershell-plugins/issues/332) Adds support to provide different credentials for the `Invoke-IcingaCheckUNCPath` plugin, to run the check for a different user account
2020

21+
### Enhancements
22+
23+
* [#348](https://github.com/Icinga/icinga-powershell-plugins/issues/348) Adds feature to `Invoke-IcingaCheckPerfCounter` to summarize an entire performance counter category, in case all instances of the check fail to prevent large outputs being written into the database
24+
2125
## 1.10.1 (2022-12-20)
2226

2327
### Bugfixes

plugins/Invoke-IcingaCheckPerfcounter.psm1

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@ function Invoke-IcingaCheckPerfCounter()
8080
$CheckPackage.AddCheck(
8181
(
8282
New-IcingaCheck -Name $counter -NoPerfData
83-
).SetUnknown($Counters[$counter].error, $TRUE)
84-
)
83+
).SetUnknown([string]::Format('Internal Counter Error: Failed to fetch performance counter. Error message: {1}', $counter, $Counters[$counter].error), $TRUE)
84+
);
8585
continue;
8686
}
8787

88+
# Set this to true, which means that by default we always fail
89+
[bool]$CounterFailed = $TRUE;
90+
[string]$FirstError = '';
91+
8892
foreach ($instanceName in $Counters[$counter].Keys) {
8993
if ((Test-IcingaArrayFilter -InputObject $instanceName -Include $IncludeCounter -Exclude $ExcludeCounter) -eq $FALSE) {
9094
continue;
@@ -93,14 +97,15 @@ function Invoke-IcingaCheckPerfCounter()
9397
$instance = $Counters[$counter][$instanceName];
9498

9599
if ([string]::IsNullOrEmpty($instance.error) -eq $FALSE) {
96-
$CounterPackage.AddCheck(
97-
(
98-
New-IcingaCheck -Name $instanceName -NoPerfData
99-
).SetUnknown($instance.error, $TRUE)
100-
)
100+
if ([string]::IsNullOrEmpty($FirstError)) {
101+
$FirstError = [string]($instance.error);
102+
}
101103
continue;
102104
}
103105

106+
# If we found atleast one working counter in this category, proceed
107+
$CounterFailed = $FALSE;
108+
104109
if ($instance -IsNot [hashtable]) {
105110
$CounterInfo = Get-IcingaPerformanceCounterDetails -Counter $counter;
106111
$IcingaCheck = New-IcingaCheck -Name $counter -Value $Counters[$counter].Value -MetricIndex $CounterInfo.Category -MetricName $CounterInfo.Counter;
@@ -114,6 +119,19 @@ function Invoke-IcingaCheckPerfCounter()
114119
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
115120
$CounterPackage.AddCheck($IcingaCheck);
116121
}
122+
123+
# If all of over counters failed for some reason, only print one combined error message.
124+
if ($CounterFailed) {
125+
if ([string]::IsNullOrEmpty($FirstError)) {
126+
$FirstError = 'No counter instances could be found';
127+
}
128+
$CounterPackage.AddCheck(
129+
(
130+
New-IcingaCheck -Name 'Internal Counter Error' -NoPerfData
131+
).SetUnknown([string]::Format('Failed to fetch all instances and objects for this performance counter. First error message: {0}', $FirstError), $TRUE)
132+
);
133+
}
134+
117135
$CheckPackage.AddCheck($CounterPackage);
118136
}
119137

0 commit comments

Comments
 (0)