Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. # Environment Variables: $AMQP_USER, $AMQP_PASSWORD, $AMQP_HOST
  2. import os
  3. from datadog import statsd
  4. from kombu import Connection, Exchange, Queue
  5.  
  6. nova_x = Exchange('nova', type='topic', durable=False)
  7. info_q = Queue('notifications.info', exchange=nova_x, durable=False,
  8. routing_key='notifications.info')
  9.  
  10. def process_msg(body, message):
  11. statsd.event(body['event_type'], str(body), alert_type=body['priority'], source_type_name='openstack', tags=['openstack'])
  12. message.ack()
  13.  
  14. AMQP_USER = os.environ['AMQP_USER']
  15. AMQP_PASSWORD = os.environ['AMQP_PASSWORD']
  16. AMQP_HOST = os.environ['AMQP_HOST']
  17.  
  18. with Connection('amqp://{0}:{1}@{2}//'.format(AMQP_USER, AMQP_PASSWORD, AMQP_HOST)) as conn:
  19. with conn.Consumer(info_q, callbacks=[process_msg]):
  20. try:
  21. while True:
  22. conn.drain_events()
  23. except KeyboardInterrupt:
  24. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement