forked from wasserja/MrANagios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Submit-NagiosXiOpenServiceProblemsAcknowledgement.ps1
51 lines (43 loc) · 2.11 KB
/
Submit-NagiosXiOpenServiceProblemsAcknowledgement.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
<#
.SYNOPSIS
Acknowledge all open service problems in Nagios XI.
.DESCRIPTION
Get a list of open service problems from Nagios XI using Invoke-NagiosXiApi and then
acknowledge each of them.
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 Comment
Provide a comment for the acknowledgement.
.EXAMPLE
Submit-NagiosXiOpenServiceProblemsAcknowledgement
#>
function Submit-NagiosXiOpenServiceProblemsAcknowledgement {
[CmdletBinding()]
[Alias()]
Param
(
[string]$NagiosXiApiUrl,
[string]$NagiosXiApiKey,
[string]$NagiosCoreUrl,
#[string]$ServiceName='*', # Maybe later we can add filtering by service name and/or by host name
[string]$Comment = 'Acknowledged by Mr. Automaton.',
# Nagios Credential
[Parameter(Mandatory = $true)]
[System.Management.Automation.PSCredential]$Credential
)
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}
foreach ($OpenServiceProblem in $OpenServiceProblems) {
Write-Verbose -Message "Submitting Nagios acknowledgement for $($OpenServiceProblem.name) on $($OpenServiceProblem.host_name)"
Submit-NagiosServiceAcknowledgement -ComputerName $OpenServiceProblem.host_name -service $OpenServiceProblem.name -comment $Comment -NagiosCoreUrl $NagiosCoreUrl -Credential $Credential
}
}
End {}
}