Skip to content

Instantly share code, notes, and snippets.

@vagelim
Created August 9, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vagelim/6fd7d53378f7947c6fb5a3cec8edbbec to your computer and use it in GitHub Desktop.
Save vagelim/6fd7d53378f7947c6fb5a3cec8edbbec to your computer and use it in GitHub Desktop.
Send Nova events to DogStatsD
# Environment Variables: $AMQP_USER, $AMQP_PASSWORD, $AMQP_HOST
import os
from datadog import statsd
from kombu import Connection, Exchange, Queue
nova_x = Exchange('nova', type='topic', durable=False)
info_q = Queue('notifications.info', exchange=nova_x, durable=False,
routing_key='notifications.info')
def process_msg(body, message):
statsd.event(body['event_type'], str(body), alert_type=body['priority'], source_type_name='openstack', tags=['openstack'])
message.ack()
AMQP_USER = os.environ['AMQP_USER']
AMQP_PASSWORD = os.environ['AMQP_PASSWORD']
AMQP_HOST = os.environ['AMQP_HOST']
with Connection('amqp://{0}:{1}@{2}//'.format(AMQP_USER, AMQP_PASSWORD, AMQP_HOST)) as conn:
with conn.Consumer(info_q, callbacks=[process_msg]):
try:
while True:
conn.drain_events()
except KeyboardInterrupt:
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment