forked from RamblingCookieMonster/RabbitMQTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-RabbitMQQueue.ps1
More file actions
130 lines (97 loc) · 4.01 KB
/
Get-RabbitMQQueue.ps1
File metadata and controls
130 lines (97 loc) · 4.01 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<#
.Synopsis
Gets open RabbitMQ Channels.
.DESCRIPTION
The Get-RabbitMQQueue cmdlet gets queues registered with RabbitMQ server.
The cmdlet allows you to show list of all queues or filter them by name using wildcards.
The result may be zero, one or many RabbitMQ.Queue objects.
To get Queues from remote server you need to provide -HostName parameter.
The cmdlet is using REST Api provided by RabbitMQ Management Plugin. For more information go to: https://www.rabbitmq.com/management.html
.EXAMPLE
Get-RabbitMQQueue
This command gets a list of all queues reigsters with local RabbitMQ server.
.EXAMPLE
Get-RabbitMQQueue -HostName myrabbitmq.servers.com
This command gets a list of all queues registerd with myrabbitmq.servers.com server.
.EXAMPLE
Get-RabbitMQQueue services*
This command gets a list of all queues which name starts with "services".
.EXAMPLE
Get-RabbitMQQueue -VirtualHost vhost1
This command gets a list of all queues in Virtual Host "vhost1".
.EXAMPLE
Get-RabbitMQQueue -NotEmpty
This command gets a list of all queues having messages.
.EXAMPLE
Get-RabbitMQQueue -ShowStats
This command shows queue statistics.
It is equivalent to running Get-RabbitMQQueue | Format-Table -View Stats
.EXAMPLE
@("services*", "posion*") | Get-RabbitMQQueue
This command pipes queue name filters to Get-RabbitMQQueue cmdlet.
.INPUTS
You can pipe queue Name, VirtualHost and HostName to filter the results.
.OUTPUTS
By default, the cmdlet returns list of RabbitMQ.Queue objects which describe RabbitMQ queue.
.LINK
https://www.rabbitmq.com/management.html - information about RabbitMQ management plugin.
#>
function Get-RabbitMQQueue
{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='None')]
Param
(
# Name of RabbitMQ queue.
[parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[Alias("queue", "QueueName")]
[string[]]$Name = "",
# Name of the computer hosting RabbitMQ server. Defalut value is localhost.
[parameter(ValueFromPipelineByPropertyName=$true)]
[Alias("HostName", "hn", "cn")]
[string]$BaseUri = $defaultComputerName,
# Name of the virtual host to filter channels by.
[parameter(ValueFromPipelineByPropertyName=$true)]
[Alias("vh", "vhost")]
[string]$VirtualHost,
# When set then returns only queues which have messages.
[switch]$NotEmpty,
# When set then displays queue statistics.
[switch]$ShowStats,
# Credentials to use when logging to RabbitMQ server.
[Parameter(Mandatory=$false)]
[PSCredential]$Credentials = $defaultCredentials
)
Begin
{
}
Process
{
if ($pscmdlet.ShouldProcess("server $BaseUri", "Get queues(s): $(NamesToString $Name '(all)')"))
{
$result = GetItemsFromRabbitMQApi -BaseUri $BaseUri $Credentials "queues"
$result = ApplyFilter $result 'name' $Name
if ($VirtualHost) { $result = ApplyFilter $result 'vhost' $VirtualHost }
foreach ($item in $result)
{
if ($item.messages -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages -Value 0 }
if ($item.messages_ready -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages_ready -Value 0 }
if ($item.messages_unacknowledged -eq $null) { $item | Add-Member -MemberType NoteProperty -Name messages_unacknowledged -Value 0 }
}
if ($NotEmpty) {
$result = $result | ? messages -ne 0
}
$result | Add-Member -NotePropertyName "HostName" -NotePropertyValue $BaseUri
if ($ShowStats)
{
SendItemsToOutput $result "RabbitMQ.Queue" | ft -View Stats
}
else
{
SendItemsToOutput $result "RabbitMQ.Queue"
}
}
}
End
{
}
}