0

I am getting a response in Rabbitmq message queue for various operations in Devstack (KILO version).

Now I need to listen to particular 'event_type' from the response.

Payload data is as follows:

\"event_type\": \"compute.instance.update\"

I have tried python code to parse the same is as follows:

def _handle_message(self, body):
    event_type = body['event_type']

Now the issues is that due to the slashes in it I am getting the error as follows:

2015-10-06 00:07:53,013 KeyError('event_type',)

I am not suppose to change the way how the responses are being sent.

I can modify the way how I am trying to parse it.

Please some one help me regarding this.

Note:

I was getting the code which I made working fine in previous versions of devstack.In those reponse data doesn't have thoses slashes.Now the main issue is with slashes.

Alternatively, In simple words what I need now is matching the \"event_type\" exactly using python code.

Murali
  • 1,084
  • 1
  • 11
  • 28
  • Are you actually parsing the JSON anywhere? E.g. using `json.loads`. – Thomas Orozco Oct 06 '15 at 07:22
  • Actually response which is getting generated was in Json format only. But in my code What I need to do is check for the event_type in body. that is from this response like this. \"event_type\": \"compute.instance.update\" – Murali Oct 06 '15 at 07:25

1 Answers1

0

If you are getting the KeyError ,it should definitely be the case that the key is not present in the dictionary.

In your case ,you are checking if the event_type is present in the body.You will have to even check json body to see if the "event_type" key is actually present as a child of the root node.The openstack event notification json format for oslo messaging is different and hence,try doing the below.

jsonbody = body['oslo.message']
event_type = jsonbody['event_type']

This should be the issue in most cases for openstack event notifications parsing.

crackerplace
  • 5,305
  • 8
  • 34
  • 42