Skip to content

Commit

Permalink
Merge pull request #352 from Icinga:feature/summarize_performance_cou…
Browse files Browse the repository at this point in the history
…nter_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
```
  • Loading branch information
LordHepipud authored Jun 1, 2023
2 parents 8b21639 + a6622d3 commit df37c12
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

* [#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

### Enhancements

* [#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

## 1.10.1 (2022-12-20)

### Bugfixes
Expand Down
32 changes: 25 additions & 7 deletions plugins/Invoke-IcingaCheckPerfcounter.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,15 @@ function Invoke-IcingaCheckPerfCounter()
$CheckPackage.AddCheck(
(
New-IcingaCheck -Name $counter -NoPerfData
).SetUnknown($Counters[$counter].error, $TRUE)
)
).SetUnknown([string]::Format('Internal Counter Error: Failed to fetch performance counter. Error message: {1}', $counter, $Counters[$counter].error), $TRUE)
);
continue;
}

# Set this to true, which means that by default we always fail
[bool]$CounterFailed = $TRUE;
[string]$FirstError = '';

foreach ($instanceName in $Counters[$counter].Keys) {
if ((Test-IcingaArrayFilter -InputObject $instanceName -Include $IncludeCounter -Exclude $ExcludeCounter) -eq $FALSE) {
continue;
Expand All @@ -93,14 +97,15 @@ function Invoke-IcingaCheckPerfCounter()
$instance = $Counters[$counter][$instanceName];

if ([string]::IsNullOrEmpty($instance.error) -eq $FALSE) {
$CounterPackage.AddCheck(
(
New-IcingaCheck -Name $instanceName -NoPerfData
).SetUnknown($instance.error, $TRUE)
)
if ([string]::IsNullOrEmpty($FirstError)) {
$FirstError = [string]($instance.error);
}
continue;
}

# If we found atleast one working counter in this category, proceed
$CounterFailed = $FALSE;

if ($instance -IsNot [hashtable]) {
$CounterInfo = Get-IcingaPerformanceCounterDetails -Counter $counter;
$IcingaCheck = New-IcingaCheck -Name $counter -Value $Counters[$counter].Value -MetricIndex $CounterInfo.Category -MetricName $CounterInfo.Counter;
Expand All @@ -114,6 +119,19 @@ function Invoke-IcingaCheckPerfCounter()
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
$CounterPackage.AddCheck($IcingaCheck);
}

# If all of over counters failed for some reason, only print one combined error message.
if ($CounterFailed) {
if ([string]::IsNullOrEmpty($FirstError)) {
$FirstError = 'No counter instances could be found';
}
$CounterPackage.AddCheck(
(
New-IcingaCheck -Name 'Internal Counter Error' -NoPerfData
).SetUnknown([string]::Format('Failed to fetch all instances and objects for this performance counter. First error message: {0}', $FirstError), $TRUE)
);
}

$CheckPackage.AddCheck($CounterPackage);
}

Expand Down

0 comments on commit df37c12

Please sign in to comment.