blob: 232ed8406451358bfeb2c84bb04c1a0f3b4353f5 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
rdudyalab086cf32016-08-11 00:07:45 -040017from kombu.connection import BrokerConnection
18from kombu.messaging import Exchange, Queue, Consumer, Producer
19import six
20import uuid
21import datetime
22
23keystone_tenant_id='3a397e70f64e4e40b69b6266c634d9d0'
24keystone_user_id='1e3ce043029547f1a61c1996d1a531a2'
25rabbit_user='openstack'
26rabbit_password='password'
27rabbit_host='localhost'
28vcpeservice_rabbit_exchange='vcpeservice'
29cpe_publisher_id='vcpe_publisher'
30
31producer = None
32
33def setup_rabbit_mq_channel():
34 global producer
35 global rabbit_user, rabbit_password, rabbit_host, vcpeservice_rabbit_exchange,cpe_publisher_id
36 vcpeservice_exchange = Exchange(vcpeservice_rabbit_exchange, "topic", durable=False)
37 # connections/channels
38 connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
39 print 'Connection to RabbitMQ server successful'
40 channel = connection.channel()
41 # produce
42 producer = Producer(channel, exchange=vcpeservice_exchange, routing_key='notifications.info')
43
44def publish_cpe_stats():
45 global producer
46 global keystone_tenant_id, keystone_user_id, cpe_publisher_id
47
48 msg = {'event_type': 'vcpe',
49 'message_id':six.text_type(uuid.uuid4()),
50 'publisher_id': cpe_publisher_id,
51 'timestamp':datetime.datetime.now().isoformat(),
52 'priority':'INFO',
53 'payload': {'vcpe_id':'vcpe-222-432',
54 'user_id': keystone_user_id,
55 'tenant_id': keystone_tenant_id
56 }
57 }
58 producer.publish(msg)
59 msg = {'event_type': 'vcpe.dns.cache.size',
60 'message_id':six.text_type(uuid.uuid4()),
61 'publisher_id': cpe_publisher_id,
62 'timestamp':datetime.datetime.now().isoformat(),
63 'priority':'INFO',
64 'payload': {'vcpe_id':'vcpe-222-432',
65 'user_id': keystone_user_id,
66 'tenant_id': keystone_tenant_id,
67 'cache_size':150
68 }
69 }
70 producer.publish(msg)
71
72if __name__ == "__main__":
73 setup_rabbit_mq_channel()
74 publish_cpe_stats()