rdudyala | b086cf3 | 2016-08-11 00:07:45 -0400 | [diff] [blame] | 1 | from kombu.connection import BrokerConnection |
| 2 | from kombu.messaging import Exchange, Queue, Consumer, Producer |
| 3 | import six |
| 4 | import uuid |
| 5 | import datetime |
| 6 | |
| 7 | keystone_tenant_id='3a397e70f64e4e40b69b6266c634d9d0' |
| 8 | keystone_user_id='1e3ce043029547f1a61c1996d1a531a2' |
| 9 | rabbit_user='openstack' |
| 10 | rabbit_password='password' |
| 11 | rabbit_host='localhost' |
| 12 | vcpeservice_rabbit_exchange='vcpeservice' |
| 13 | cpe_publisher_id='vcpe_publisher' |
| 14 | |
| 15 | producer = None |
| 16 | |
| 17 | def setup_rabbit_mq_channel(): |
| 18 | global producer |
| 19 | global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id |
| 20 | vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False) |
| 21 | # connections/channels |
| 22 | connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password) |
| 23 | print 'Connection to RabbitMQ server successful' |
| 24 | channel = connection.channel() |
| 25 | # produce |
| 26 | producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info') |
| 27 | |
| 28 | def publish_cpe_stats(): |
| 29 | global producer |
| 30 | global keystone_tenant_id, keystone_user_id, cpe_publisher_id |
| 31 | |
| 32 | msg = {'event_type': 'vcpe', |
| 33 | 'message_id':six.text_type(uuid.uuid4()), |
| 34 | 'publisher_id': cpe_publisher_id, |
| 35 | 'timestamp':datetime.datetime.now().isoformat(), |
| 36 | 'priority':'INFO', |
| 37 | 'payload': {'vcpe_id':'vcpe-222-432', |
| 38 | 'user_id': keystone_user_id, |
| 39 | 'tenant_id': keystone_tenant_id |
| 40 | } |
| 41 | } |
| 42 | producer.publish(msg) |
| 43 | msg = {'event_type': 'vcpe.dns.cache.size', |
| 44 | 'message_id':six.text_type(uuid.uuid4()), |
| 45 | 'publisher_id': cpe_publisher_id, |
| 46 | 'timestamp':datetime.datetime.now().isoformat(), |
| 47 | 'priority':'INFO', |
| 48 | 'payload': {'vcpe_id':'vcpe-222-432', |
| 49 | 'user_id': keystone_user_id, |
| 50 | 'tenant_id': keystone_tenant_id, |
| 51 | 'cache_size':150 |
| 52 | } |
| 53 | } |
| 54 | producer.publish(msg) |
| 55 | |
| 56 | if __name__ == "__main__": |
| 57 | setup_rabbit_mq_channel() |
| 58 | publish_cpe_stats() |