-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathGet-IcingaWindowsServiceStatus.psm1
More file actions
53 lines (48 loc) · 1.95 KB
/
Get-IcingaWindowsServiceStatus.psm1
File metadata and controls
53 lines (48 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function Get-IcingaWindowsServiceStatus()
{
param (
[string]$Service = '',
[switch]$Force = $FALSE
);
if ($Service -eq 'icinga2' -Or $Service -eq 'icingapowershell') {
if ($Service -eq 'icinga2') {
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IcingaServiceState) -eq $FALSE) {
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
return @{
'Status' = $Global:Icinga.Protected.IcingaServiceState;
'Present' = $TRUE;
'Name' = $Service;
'DisplayName' = $Service;
};
}
}
} elseif ($Service -eq 'icingapowershell') {
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.IfWServiceState) -eq $FALSE) {
if ($Global:Icinga.Protected.ServiceRestartLock -And $Force -eq $FALSE) {
return @{
'Status' = $Global:Icinga.Protected.IfWServiceState;
'Present' = $TRUE;
'Name' = $Service;
'DisplayName' = $Service;
};
}
}
}
}
$ServiceData = Invoke-IcingaWindowsScheduledTask -JobType 'GetWindowsService' -ObjectName $Service;
if ($ServiceData.Service.Installed -eq $FALSE) {
Write-IcingaConsoleError $ServiceData.ErrMsg;
return @{
'Status' = '';
'Present' = $FALSE;
'Name' = 'Unknown';
'DisplayName' = 'Unknown';
};
}
if ($Service -eq 'icinga2') {
$Global:Icinga.Protected.IcingaServiceState = $ServiceData.Service.Status;
} elseif ($Service -eq 'icingapowershell') {
$Global:Icinga.Protected.IfWServiceState = $ServiceData.Service.Status;
}
return $ServiceData.Service;
}