blob: 807672dfd082016078981135236ddf36916b5aa0 [file] [log] [blame]
rdudyalab086cf32016-08-11 00:07:45 -04001#
2# Copyright 2012 New Dream Network, LLC (DreamHost)
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# 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, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15"""Handler for producing network counter messages from Neutron notification
16 events.
17
18"""
19
20import oslo_messaging
21from oslo_config import cfg
22
23from ceilometer.agent import plugin_base
24from oslo_log import log
25from ceilometer import sample
26
27OPTS = [
28 cfg.StrOpt('openstack_infra_service_control_exchange',
29 default='openstack_infra',
30 help="Exchange name for INFRA notifications."),
31]
32
33cfg.CONF.register_opts(OPTS)
34
35LOG = log.getLogger(__name__)
36
37
38class OPENSTACK_INFRANotificationBase(plugin_base.NotificationBase):
39
40 resource_name = None
41
42 def get_targets(self,conf):
43 """Return a sequence of oslo.messaging.Target
44 This sequence is defining the exchange and topics to be connected for
45 this plugin.
46 """
47 LOG.info("get_targets for OPENSTACK INFRA Notification Listener")
48 return [oslo_messaging.Target(topic=topic,
49 exchange=conf.openstack_infra_service_control_exchange)
50 for topic in self.get_notification_topics(conf)]
51
52class OPENSTACK_INFRANotification(OPENSTACK_INFRANotificationBase):
53
54 resource_name = None
55 event_types = ['infra$']
56
57 def process_notification(self, message):
58 LOG.info('Received OPENSTACK INFRA notification: resource_id =%(resource_id)s' % {'resource_id': message['payload']['resource_id']})
59 yield sample.Sample.from_notification(
60 name=message['payload']['counter_name'],
61 type=message['payload']['counter_type'],
62 unit=message['payload']['counter_unit'],
63 volume=message['payload']['counter_volume'],
64 user_id=message['payload']['user_id'],
65 project_id=message['payload']['project_id'],
66 resource_id=message['payload']['resource_id'],
67 message=message)