blob: a832b01eb1837148559e9cf3ddaa48ebe5a38f01 [file] [log] [blame]
Srikanth Vavilapallib66304b2017-01-19 20:25:19 +00001#
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('cord_control_exchange',
29 default='cord',
30 help="Exchange name for CORD related notifications."),
31]
32
33cfg.CONF.register_opts(OPTS)
34
35LOG = log.getLogger(__name__)
36
37
38class CORDNotificationBase(plugin_base.NotificationBase):
39
40 resource_name = None
41 event_types = ['cord*']
42
43 def get_targets(self,conf):
44 """Return a sequence of oslo.messaging.Target
45
46 This sequence is defining the exchange and topics to be connected for
47 this plugin.
48 """
49 LOG.info("get_targets for CORD Notification Listener")
50 return [oslo_messaging.Target(topic=topic,
51 exchange=conf.cord_control_exchange)
52 for topic in self.get_notification_topics(conf)]
53
54 def process_notification(self, message):
55 LOG.info('Received CORD notification')
56 if 'counter_type' not in message['payload']:
57 meter_type = sample.TYPE_GAUGE
58 else:
59 meter_type = sample.TYPE_GAUGE if 'gauge' in message['payload']['counter_type'].lower() else sample.TYPE_DELTA if 'delta' in message['payload']['counter_type'].lower() else sample.TYPE_GAUGE
60
61 yield sample.Sample.from_notification(
62 name=message['payload']['counter_name'],
63 type=meter_type,
64 unit=message['payload']['counter_unit'],
65 volume=message['payload']['counter_volume'],
66 user_id=message['payload']['user_id'],
67 project_id=message['payload']['tenant_id'],
68 resource_id=message['payload']['resource_id'],
69 message=message)