Skip to content

Commit a6622d3

Browse files
committed
Adds feature to summarize perf counter errors for all failed instances
1 parent e50170d commit a6622d3

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
@@ -13,6 +13,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1313

1414
* [#342](https://github.com/Icinga/icinga-powershell-plugins/issues/342) Fixes an issue for disk health plugin, which can fail in some cases due to an invalid conversion from the MSFT output from int to string
1515

16+
### Enhancements
17+
18+
* [#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
19+
1620
## 1.10.1 (2022-12-20)
1721

1822
### 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)