2014-02-18 11:53:41 +04:00
|
|
|
#!/usr/bin/env python
|
2014-04-16 22:40:15 +04:00
|
|
|
|
2014-02-25 21:55:02 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2014-04-16 22:40:15 +04:00
|
|
|
# Copyright (c) 2014 Mozilla Corporation
|
|
|
|
#
|
|
|
|
# Contributors:
|
|
|
|
# Jeff Bryner jbryner@mozilla.com
|
2014-02-25 21:55:02 +04:00
|
|
|
|
2014-02-18 11:53:41 +04:00
|
|
|
import pika
|
|
|
|
import sys
|
|
|
|
|
|
|
|
connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost'))
|
|
|
|
channel = connection.channel()
|
|
|
|
|
|
|
|
channel.exchange_declare(exchange='alerts',type='topic')
|
|
|
|
|
|
|
|
result = channel.queue_declare(exclusive=True)
|
|
|
|
queue_name = result.method.queue
|
|
|
|
|
|
|
|
binding_keys = sys.argv[1:]
|
|
|
|
if not binding_keys:
|
|
|
|
print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
for binding_key in binding_keys:
|
|
|
|
channel.queue_bind(exchange='alerts',
|
|
|
|
queue=queue_name,
|
|
|
|
routing_key=binding_key)
|
|
|
|
|
|
|
|
print ' [*] Waiting for logs. To exit press CTRL+C'
|
|
|
|
|
|
|
|
def callback(ch, method, properties, body):
|
|
|
|
print " [x] %r:%r" % (method.routing_key, body,)
|
|
|
|
|
|
|
|
channel.basic_consume(callback,
|
|
|
|
queue=queue_name,
|
|
|
|
no_ack=True)
|
|
|
|
|
|
|
|
channel.start_consuming()
|