Skip to content

Commit c7d0a92

Browse files
committed
Prefer starttype of services fetching over WMI
1 parent d164fae commit c7d0a92

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818
* [#186](https://github.com/Icinga/icinga-powershell-framework/issues/186) Fixes path handling for custom local/web path sources for service binary installation
1919
* [#188](https://github.com/Icinga/icinga-powershell-framework/pull/188) Removes hardcoded zones `director-global` and `global-zones` which were always set regardless of user specification. This fix will ensure the user has the option to add or not add these zones
2020
* [#189](https://github.com/Icinga/icinga-powershell-framework/pull/189) Fixes wrong documented user group for accessing Performance Counter objects which should be `Performance Monitor Users`
21+
* [#192](https://github.com/Icinga/icinga-powershell-framework/pull/192) Fixes code base for `Invoke-IcingaCheckService` by preferring to fetch the startup type of services by using WMI instead of `Get-Services`, as the result of `Get-Services` might be empty in some cases
2122
* [#195](https://github.com/Icinga/icinga-powershell-framework/pull/195) Fix Agent installer crash on package lookup with different files in directory
2223
* [#197](https://github.com/Icinga/icinga-powershell-framework/pull/197) Fixes progress bar appearance on check outputs for certain plugins, by disabling the entire PowerShell progress bar during the usage of Icinga for Windows
2324

lib/core/tools/Get-IcingaServices.psm1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function Get-IcingaServices()
2626
[array]$DependingServices = $null;
2727
$ServiceExitCode = 0;
2828
[string]$ServiceUser = '';
29+
[int]$StartModeId = 5;
30+
[string]$StartMode = 'Unknown';
2931

3032
if ($Exclude -contains $service.ServiceName) {
3133
continue;
@@ -35,6 +37,10 @@ function Get-IcingaServices()
3537
if ($wmiService.Name -eq $service.ServiceName) {
3638
$ServiceUser = $wmiService.StartName;
3739
$ServiceExitCode = $wmiService.ExitCode;
40+
if ([string]::IsNullOrEmpty($wmiService.StartMode) -eq $FALSE) {
41+
$StartModeId = ([int]$IcingaEnums.ServiceWmiStartupType[$wmiService.StartMode]);
42+
$StartMode = $IcingaEnums.ServiceStartupTypeName[$StartModeId];
43+
}
3844
break;
3945
}
4046
}
@@ -80,8 +86,8 @@ function Get-IcingaServices()
8086
};
8187
'ServiceHandle' = $service.ServiceHandle;
8288
'StartType' = @{
83-
'raw' = [int]$service.StartType;
84-
'value' = $service.StartType;
89+
'raw' = $StartModeId;
90+
'value' = $StartMode;
8591
};
8692
'ServiceUser' = $ServiceUser;
8793
'ExitCode' = $ServiceExitCode;

lib/icinga/enums/Icinga_IcingaEnums.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@
3838
'c' = 'counter';
3939
};
4040

41+
<##################################################################################################
42+
################# Service Enums ##################################################################
43+
##################################################################################################>
44+
45+
[hashtable]$ServiceStartupTypeName = @{
46+
0 = 'Boot';
47+
1 = 'System';
48+
2 = 'Automatic';
49+
3 = 'Manual';
50+
4 = 'Disabled';
51+
5 = 'Unknown'; # Custom
52+
}
53+
54+
[hashtable]$ServiceWmiStartupType = @{
55+
'Boot' = 0;
56+
'System' = 1;
57+
'Auto' = 2;
58+
'Manual' = 3;
59+
'Disabled' = 4;
60+
'Unknown' = 5; # Custom
61+
}
62+
4163
<#
4264
# Once we defined a new enum hashtable above, simply add it to this list
4365
# to make it available within the entire module.
@@ -50,6 +72,9 @@
5072
IcingaExitCodeText = $IcingaExitCodeText;
5173
IcingaExitCodeColor = $IcingaExitCodeColor;
5274
IcingaMeasurementUnits = $IcingaMeasurementUnits;
75+
#services
76+
ServiceStartupTypeName = $ServiceStartupTypeName;
77+
ServiceWmiStartupType = $ServiceWmiStartupType;
5378
}
5479

5580
Export-ModuleMember -Variable @( 'IcingaEnums' );

0 commit comments

Comments
 (0)