Created
August 9, 2016 12:43
-
-
Save vagelim/6fd7d53378f7947c6fb5a3cec8edbbec to your computer and use it in GitHub Desktop.
Send Nova events to DogStatsD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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