Skip to content

Commit 19a6952

Browse files
committed
Improve test if perf counter category exist
1 parent d6f1644 commit 19a6952

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1919
* [#235](https://github.com/Icinga/icinga-powershell-framework/pull/235) Adds new Cmdlet `Show-IcingaEventLogAnalysis` to get a better overview on how many log entries are present within the EventLog based on hour, minute and day average/maximum for allowing a more dynamic configuration for `Invoke-IcingaCheckEventLog`
2020
* [#241](https://github.com/Icinga/icinga-powershell-framework/pull/241) Ensures we use TLS 1.1 and 1.2 for REST-Api calls, as used certificates in general are created with these
2121
* [#243](https://github.com/Icinga/icinga-powershell-framework/pull/243) Adds stacktrace output for exceptions in case plugin execution fails
22+
* [#248](https://github.com/Icinga/icinga-powershell-framework/pull/248) Improves `Test-IcingaPerformanceCounterCategory` by creating an object for the Performance Counter category provided and checking if it is a valid object instead of relying on the registry which might not contain all categories in the correct language.
2223

2324
### Bugfixes
2425

lib/core/perfcounter/Test-IcingaPerformanceCounterCategory.psm1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ function Test-IcingaPerformanceCounterCategory()
2828
[string]$Category
2929
);
3030

31-
$Counters = Show-IcingaPerformanceCounterCategories -Filter $Category;
31+
if ([string]::IsNullOrEmpty($Category)) {
32+
return $FALSE;
33+
}
34+
35+
try {
36+
$Counter = New-Object System.Diagnostics.PerformanceCounterCategory($Category);
3237

33-
if ($Counters.Count -eq 0) {
38+
if ($null -eq $Counter -Or [string]::IsNullOrEmpty($Counter.CategoryType)) {
39+
return $FALSE;
40+
}
41+
} catch {
3442
return $FALSE;
3543
}
3644

0 commit comments

Comments
 (0)