Home > openstack > Intercepting internal messages from RabbitMQ in OpenStack Nova

Intercepting internal messages from RabbitMQ in OpenStack Nova

Suppose, you are the OpenStack Cloud Admin of your company and you want whenever, a new vm is created or updated or deleted you want to be informed of the details. Similarly, you need to know (as a admin) about various other  cloud actions(snapshot creation, vm resize and so on). Typically, each action send one or more notification. For example, when booting a new VM, four different (but co-related) notifications are sent.

Event_type extracted from a notification messages associated with vm creation process are :

compute.instance.update
scheduler.run_instance.start
scheduler.run_instance.scheduled
scheduler.run_instance.end

Limited details of the compute.instance.update message associated with vm creation process is follows:

{
"_context_request_id":"req-2e8069cd-8f68-4bc7-9742-8e76365b761c",
"event_type":"compute.instance.update",
"payload.instance_id":"47e912b9-3680-4a66-a070-791728c4d241",
"payload.state_description":"scheduling",
"_unique_id":"94e000b4955448e889c1db1ed674e57d",
"payload.hostname":"new-vm"
}

 

The following is an excerpt from nova scheduler showing sendings a notification named *scheduler.run_instance.start* for the vm creation process.

notifier

Now, We need to know where these notifications are sent and how to capture them. In fact, these notifications are being sent to message queues named notifications.info, notification.error.

notification_queue

Above figure, shows two different queues named ‘notifications.info’ and ‘notifications.error’ which capture info messages and error messages correspondingly.

We can fetch this notifications messages in following ways out of many possibilities.

1. Attach a consumer to the notifications.info or notifications.error queue. In some cases, attaching a consumer may not be desirable if there are multiple consumer which forces the messages to be dispatched to the consumer in a round-robin fashion.

2. Intercept the notification messages from the “nova” exchange and attach your own queue for notifications in which case notifications are forward to the newly defined queue as well as predefined ‘notification.info’ queues.

Following code snippet shows how to connect to the notifications.info queue and extract notification messages.

import pika
class MessageBroker:</code>

def __init__(self):
    queue_name = 'notifications.info'
    parameters = pika.URLParameters('amqp://guest:admin@localhost:5672/%2F') #my      devstack conf.
    connection = pika.BlockingConnection(parameters)

    channel = connection.channel()
    channel.queue_declare(queue= queue_name)
    print ' [*] Waiting for messages. To exit press CTRL+C'
    channel.basic_consume(self.callback,
    queue= queue_name,no_ack=True)

    channel.start_consuming()

    def callback(self, ch, method, properties, body):

    print body
    print "\n"

def receive_message():
    MessageBroker()
    receive_message()

Advertisements
  1. May 8, 2014 at 1:10 am

    Thanks for writing about Notification in Openstack.

    What sort of changes needed in nova.conf, and can we create/modify notifications?

  2. June 1, 2015 at 12:48 am

    Inspired by your article I created a Nova notification listener using Kombu messaging library:
    http://alesnosek.com/blog/2015/05/25/openstack-nova-notifications-subscriber/

    Blogpost explains the necessary Nova configuration, too.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: