blob: eb84a2f76ad6687c29ad0e928d700f90436d9489 [file] [log] [blame]
rdudyalab086cf32016-08-11 00:07:45 -04001from kombu.connection import BrokerConnection
2from kombu.messaging import Exchange, Queue, Consumer, Producer
3import six
4import uuid
5import datetime
6
7keystone_tenant_id='3a397e70f64e4e40b69b6266c634d9d0'
8keystone_user_id='1e3ce043029547f1a61c1996d1a531a2'
9rabbit_user='openstack'
10rabbit_password='password'
11rabbit_host='localhost'
12vcpeservice_rabbit_exchange='vcpeservice'
13cpe_publisher_id='vcpe_publisher'
14
15producer = None
16
17def 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
28def 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
56if __name__ == "__main__":
57 setup_rabbit_mq_channel()
58 publish_cpe_stats()