Merge pull request #807 from Icinga:fix/ifw_freezes_for_services_blocking_cim_requests

Fix: Icinga for Windows being stuck while fetching service information if other services block CIM requests

Fixes Icinga for Windows being stuck during installation while fetching service information over CIM-Instances, if other services are frozen, blocking the CIM-Request
This commit is contained in:
Lord Hepipud 2025-04-22 14:47:30 +02:00 committed by GitHub
commit 9beba0e854
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 17 deletions

View file

@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#781](https://github.com/Icinga/icinga-powershell-framework/issues/781) Fixes Icinga for Windows being stuck during installation while fetching service information over CIM-Instances, if other services are frozen, blocking the CIM-Request
* [#784](https://github.com/Icinga/icinga-powershell-framework/issues/784) Fixes Icinga for Windows threshold comparison which wrongly compared warning/critical thresholds for non-range values (like Match)
* [#785](https://github.com/Icinga/icinga-powershell-framework/issues/785) Fixes Icinga for Windows freezing during loading in case the `config.json` is empty
* [#786](https://github.com/Icinga/icinga-powershell-framework/issues/786) Fixes Icinga for Windows installer to always force the installation of the service, to ensure it is present

View file

@ -1,30 +1,66 @@
function Get-IcingaServices()
{
param (
[array]$Service,
[array]$Service = @(),
[array]$Exclude = @()
);
$ServiceInformation = Get-Service;
$ServiceWmiInfo = $null;
$ServiceFilter = New-Object System.Text.StringBuilder;
if ($Service.Count -eq 0) {
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service;
} else {
try {
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
ForEach-Object {
foreach ($svc in $Service) {
if ($_.Name -Like $svc) {
return $_;
}
}
} | Select-Object StartName, Name, ExitCode, StartMode, PathName;
} catch {
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
return $null;
if ($Service.Count -gt 0) {
$ServiceFilter.Append('(') | Out-Null;
foreach ($svc in $Service) {
if ($ServiceFilter.Length -gt 1) {
$ServiceFilter.Append(' OR ') | Out-Null;
}
$ServiceFilter.Append(
[string]::Format(
'Name LIKE "{0}"',
$svc.Replace('*', '%')
)
) | Out-Null;
}
$ServiceFilter.Append(')') | Out-Null;
}
if ($Exclude.Count -gt 0) {
if ($ServiceFilter.Length -gt 0) {
$ServiceFilter.Append(' AND (') | Out-Null;
} else {
$ServiceFilter.Append('(') | Out-Null;
}
[bool]$First = $TRUE;
foreach ($svc in $Exclude) {
if ($First -eq $FALSE) {
$ServiceFilter.Append(' AND ') | Out-Null;
}
$First = $FALSE;
$ServiceFilter.Append(
[string]::Format(
'NOT Name LIKE "{0}"',
$svc.Replace('*', '%')
)
) | Out-Null;
}
$ServiceFilter.Append(')') | Out-Null;
}
try {
$ServiceWmiInfo = Get-IcingaWindowsInformation -ClassName Win32_Service -Filter $ServiceFilter.ToString() | Select-Object StartName, Name, ExitCode, StartMode, PathName;
} catch {
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
return $null;
}
if ($null -eq $ServiceInformation) {