forked from cockpit-project/bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect-queue
executable file
·64 lines (53 loc) · 2.35 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
#!/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 sys
from task import distributed_queue
MAX_PRIORITY = 9
def main():
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('--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):
if q.declare_results[queue] is None:
print(f"queue {queue} does not exist")
return
message_count = q.declare_results[queue].method.message_count
if message_count == 0:
print(f"queue {queue} is empty")
return
for i in range(message_count):
method_frame, header_frame, body = q.channel.basic_get(queue=queue)
if method_frame:
print(body.decode())
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())