-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGet-NagiosXiHostStatus.ps1
79 lines (63 loc) · 2.06 KB
/
Get-NagiosXiHostStatus.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
71
72
73
74
75
76
77
78
79
<#
.SYNOPSIS
Get a list of host status from Nagios XI.
.DESCRIPTION
Get a list of host status from Nagios XI using Invoke-NagiosXiApi.
All parameters have default values, but you should change your NagiosXiApiUrl and NagiosXiApiKey to match
your environment. See the documentation for Invoke-NagiosXiApi.
.PARAMETER HostName
Provide the name of a monitored host. You can also provide multiple host names. Additionally
you can use a matching keyword "lk" to search for hosts matching a specific string.
.EXAMPLE
Get-NagiosXiHostStatus
Returns the status for all hosts in Nagios.
.EXAMPLE
Get-NagiosXiHostStatus -HostName SERVER01
Returns the host status for server named server01.
.EXAMPLE
Get-NagiosXiHostStatus -HostName SERVER01,SERVER02
Returns the host status for server named server01 and server02.
.EXAMPLE
Get-NagiosXiHostStatus -Query 'lk:server'
Returns the host status for any Nagios hosts with the string server in the name.
#>
function Get-NagiosXiHostStatus {
[CmdletBinding()]
[Alias()]
Param
(
[string]$NagiosXiApiUrl,
[string]$NagiosXiApiKey,
[string]$Resource = 'objects/hoststatus',
[string]$Method = 'Get',
[string[]]$HostName,
[switch]$Summary
)
Begin {}
Process {
# Build Hostname list into Query
if ($HostName) {
if ($HostName.Count -gt 1) {
$Query = "name=in:"
foreach ($Host in $HostName) {
$Query += "$Host,"
}
}
else {
$Query = "name=$HostName"
}
}
else {
$Query = $null
}
Write-Verbose "Query $Query"
$HostStatus = Invoke-NagiosXIApi -NagiosXiApiUrl $NagiosXiApiUrl -Resource $Resource -Method $Method -Query $Query -NagiosXiApiKey $NagiosXiApiKey
if ($Summary) {
$HostStatus.hoststatus | Select-Object -Property name, status_text, last_check
}
else {
$HostStatus.hoststatus
}
}
End {}
}