Skip to content

Commit 05e64dc

Browse files
committed
Fixes Icinga for Windows being stuck while fetching service information if other services block CIM requests
1 parent 824f21e commit 05e64dc

File tree

2 files changed

+54
-17
lines changed

2 files changed

+54
-17
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1515

1616
### Bugfixes
1717

18+
* [#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
1819
* [#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)
1920
* [#785](https://github.com/Icinga/icinga-powershell-framework/issues/785) Fixes Icinga for Windows freezing during loading in case the `config.json` is empty
2021
* [#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

lib/core/tools/Get-IcingaServices.psm1

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,66 @@
11
function Get-IcingaServices()
22
{
33
param (
4-
[array]$Service,
4+
[array]$Service = @(),
55
[array]$Exclude = @()
66
);
77

88
$ServiceInformation = Get-Service;
99
$ServiceWmiInfo = $null;
10+
$ServiceFilter = New-Object System.Text.StringBuilder;
1011

11-
if ($Service.Count -eq 0) {
12-
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service;
13-
} else {
14-
try {
15-
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
16-
ForEach-Object {
17-
foreach ($svc in $Service) {
18-
if ($_.Name -Like $svc) {
19-
return $_;
20-
}
21-
}
22-
} | Select-Object StartName, Name, ExitCode, StartMode, PathName;
23-
} catch {
24-
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
25-
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
26-
return $null;
12+
if ($Service.Count -gt 0) {
13+
$ServiceFilter.Append('(') | Out-Null;
14+
15+
foreach ($svc in $Service) {
16+
if ($ServiceFilter.Length -gt 1) {
17+
$ServiceFilter.Append(' OR ') | Out-Null;
18+
}
19+
20+
$ServiceFilter.Append(
21+
[string]::Format(
22+
'Name LIKE "{0}"',
23+
$svc.Replace('*', '%')
24+
)
25+
) | Out-Null;
26+
}
27+
28+
$ServiceFilter.Append(')') | Out-Null;
29+
}
30+
31+
if ($Exclude.Count -gt 0) {
32+
if ($ServiceFilter.Length -gt 0) {
33+
$ServiceFilter.Append(' AND (') | Out-Null;
34+
} else {
35+
$ServiceFilter.Append('(') | Out-Null;
36+
}
37+
38+
[bool]$First = $TRUE;
39+
40+
foreach ($svc in $Exclude) {
41+
if ($First -eq $FALSE) {
42+
$ServiceFilter.Append(' AND ') | Out-Null;
43+
}
44+
45+
$First = $FALSE;
46+
47+
$ServiceFilter.Append(
48+
[string]::Format(
49+
'NOT Name LIKE "{0}"',
50+
$svc.Replace('*', '%')
51+
)
52+
) | Out-Null;
2753
}
54+
55+
$ServiceFilter.Append(')') | Out-Null;
56+
}
57+
58+
try {
59+
$ServiceWmiInfo = Get-IcingaWindowsInformation -ClassName Win32_Service -Filter $ServiceFilter.ToString() | Select-Object StartName, Name, ExitCode, StartMode, PathName;
60+
} catch {
61+
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
62+
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
63+
return $null;
2864
}
2965

3066
if ($null -eq $ServiceInformation) {

0 commit comments

Comments
 (0)