-
Notifications
You must be signed in to change notification settings - Fork 32
/
inspect-queue
executable file
·67 lines (56 loc) · 2.54 KB
/
inspect-queue
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
#!/usr/bin/env python3
# This file is part of Cockpit.
#
# Copyright (C) 2018 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
import argparse
import json
import sys
from task import distributed_queue
MAX_PRIORITY = 9
def main() -> int:
parser = argparse.ArgumentParser(description='Read and print messages from the queue without acknowleding them')
parser.add_argument('--amqp', default=distributed_queue.DEFAULT_AMQP_SERVER,
help='The host:port of the AMQP server to consume from (default: %(default)s)')
parser.add_argument('--human', action='store_true', help="Print the 'human' field, if present")
parser.add_argument('--secrets-dir', default=distributed_queue.DEFAULT_SECRETS_DIR,
help='Directory with ca.pem and amqp-client.{pem,key} (default: %(default)s)')
opts = parser.parse_args()
with distributed_queue.DistributedQueue(opts.amqp, ['public', 'rhel', 'statistics', 'webhook'],
secrets_dir=opts.secrets_dir, passive=True) as q:
def print_queue(queue: str) -> None:
message_count = q.queue_counts.get(queue, 0)
if message_count == 0:
print(f"queue {queue} does not exist or is empty")
return
for _ in range(message_count):
method_frame, _header_frame, message = q.channel.basic_get(queue=queue)
if method_frame and message:
body = json.loads(message)
if opts.human and 'human' in body:
print(body['human'])
else:
print(body)
print('public queue:')
print_queue('public')
print('rhel queue:')
print_queue('rhel')
print('statistics queue:')
print_queue('statistics')
print('webhook queue:')
print_queue('webhook')
return 0
if __name__ == '__main__':
sys.exit(main())