Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

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

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