Fixes notice message for not found instances during performance counter cache update

This commit is contained in:
Lord Hepipud 2026-01-28 16:32:50 +01:00
parent 4a40a001e8
commit 7661054f63
2 changed files with 15 additions and 10 deletions

View file

@ -1,12 +1,14 @@
<#
.SYNOPSIS
Displays all available instances for a provided Performance Counter
Displays all available instances for a provided Performance Counter
.DESCRIPTION
Displays all available instances for a provided Performance Counter
Displays all available instances for a provided Performance Counter
.FUNCTIONALITY
Displays all available instances for a provided Performance Counter
Displays all available instances for a provided Performance Counter
.PARAMETER Counter
The name of the Performance Counter to fetch data for
The name of the Performance Counter to fetch data for
.PARAMETER NoNoticeOnMissingInstances
If specified, no notice will be displayed if no instances are found for the provided counter
.EXAMPLE
PS>Show-IcingaPerformanceCounterInstances -Counter '\Processor(*)\% processor time';
@ -25,7 +27,8 @@
function Show-IcingaPerformanceCounterInstances()
{
param (
[string]$Counter
[string]$Counter,
[switch]$NoNoticeOnMissingInstances = $FALSE
);
[hashtable]$Instances = @{ };
@ -45,9 +48,11 @@ function Show-IcingaPerformanceCounterInstances()
}
if ($Instances.Count -eq 0) {
Write-IcingaConsoleNotice `
-Message 'No instances were found for Performance Counter "{0}". Please ensure the provided counter has instances and you are using "*" for the instance name.' `
-Objects $Counter;
if ($NoNoticeOnMissingInstances -eq $FALSE) {
Write-IcingaConsoleNotice `
-Message 'No instances were found for Performance Counter "{0}". Please ensure the provided counter has instances and you are using "*" for the instance name.' `
-Objects $Counter;
}
return;
}
@ -55,4 +60,4 @@ function Show-IcingaPerformanceCounterInstances()
return (
$Instances.GetEnumerator() | Sort-Object Name
);
}
}e

View file

@ -37,7 +37,7 @@ function Update-IcingaPerformanceCounterCache()
# First we need to prepare some data by fetching the current instances of the counter
# and the cached instances. We will then compare them and update the cache accordingly
[array]$CounterInstances = Show-IcingaPerformanceCounterInstances -Counter $Counter;
[array]$CounterInstances = Show-IcingaPerformanceCounterInstances -Counter $Counter -NoNoticeOnMissingInstances;
[array]$CachedInstances = $Global:Icinga.Private.PerformanceCounter.Cache[$Counter];
[array]$UpdatedInstances = @();
[array]$CachedInstanceNames = $CachedInstances.FullName;