-
Notifications
You must be signed in to change notification settings - Fork 2
/
Resolve-NagiosXiStoppedServices.ps1
70 lines (56 loc) · 2.93 KB
/
Resolve-NagiosXiStoppedServices.ps1
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
.SYNOPSIS
Execute the Start-StoppedAutomaticService script against all open Automatic Windows Services
service problems in Nagios XI.
.DESCRIPTION
Using the Nagios XI API we can get a list of all open service problems. We can filter this list
of open service problems for Windows automatic services to attempt to resolve the issue. The
resolution involves running the Start-StoppedAutomaticService script against the server to start
any stopped automatic services. Start-StoppedAutomaticService is part of the MrAWindowsServices
module (Install-Module MrAWindowsServices).
Open service problems are services in Nagios that are warning, critical, or unknown and that
have not been acknowledged on all servers including those that are up and not in a
scheduled down time.
All parameters have default values, but you should change your NagiosXiApiUrl and NagiosXiApiKey to match
your environment. See the documentation for Invoke-NagiosXiApi.
.PARAMETER ComputerName
Filter by specific computer/host names.
.PARAMETER ServiceName
Filter by specific Nagios service. (i.e. MSSQLSERVER)
.PARAMETER Comment
Provide a comment for the acknowledgement.
.EXAMPLE
Resolve-NagiosXiStoppedServiceProblems
.EXAMPLE
Resolve-NagiosXiStoppedServiceProblems -ServiceName 'MSSQLSERVER'
Checks nagios for any open service problems with the name MSSQLSERVER and then runs
Start-StoppedAutomaticService against the computer/host name associated.
#>
#requires -Modules MrAWindowsServices
function Resolve-NagiosXiStoppedServiceProblems {
[CmdletBinding()]
[Alias()]
Param
(
[string]$NagiosXiApiUrl,
[string]$NagiosXiApiKey,
[string]$NagiosCoreUrl,
[string]$ComputerName = '*',
[string]$ServiceName = 'MSSQLSERVER|W3CSVC'
)
Begin {}
Process {
Write-Verbose 'Getting Nagios XI open service problems.'
$AllOpenServiceProblems = Get-NagiosXIAllOpenServiceProblems -NagiosXiApiUrl $NagiosXiApiUrl -NagiosXiApiKey $NagiosXiApiKey
$AllHostProblems = Get-NagiosXIAllHostProblems -NagiosXiApiUrl $NagiosXiApiUrl -NagiosXiApiKey $NagiosXiApiKey
$OpenServiceProblems = $AllOpenServiceProblems | Where-Object -FilterScript {$AllHostProblems.name -notcontains $_.host_name}
$FilteredServiceProblems = $OpenServiceProblems | Where-Object -FilterScript {$_.host_name -like $ComputerName -and $_.name -match $ServiceName}
foreach ($FilteredServiceProblem in $FilteredServiceProblems) {
Write-Verbose -Message "Starting stopped automatic services on $($FilteredServiceProblem.host_name)"
# We have a problem with permissions here. We will need a way to provide credentials for executing the resolution command.
# For now we will assume the account running this has permissions.
Start-StoppedAutomaticService -ComputerName $FilteredServiceProblem.host_name
}
}
End {}
}