Srikanth Vavilapalli | 21d1475 | 2016-09-02 01:37:34 +0000 | [diff] [blame] | 1 | # |
| 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 | |
| 20 | import oslo_messaging |
| 21 | from oslo_config import cfg |
| 22 | |
| 23 | from ceilometer.agent import plugin_base |
| 24 | from oslo_log import log |
| 25 | from ceilometer import sample |
| 26 | |
| 27 | OPTS = [ |
| 28 | cfg.StrOpt('broadview_control_exchange', |
| 29 | default='broadview_service', |
| 30 | help="Exchange name for Broadview notifications."), |
| 31 | ] |
| 32 | |
| 33 | cfg.CONF.register_opts(OPTS) |
| 34 | |
| 35 | LOG = log.getLogger(__name__) |
| 36 | |
| 37 | |
| 38 | class BroadViewNotificationBase(plugin_base.NotificationBase): |
| 39 | |
| 40 | resource_name = None |
| 41 | event_types = ['broadview.bst.*'] |
| 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("SRIKANTH: get_targets for BroadView Notification Listener") |
| 50 | return [oslo_messaging.Target(topic=topic, |
| 51 | exchange=conf.broadview_control_exchange) |
| 52 | for topic in self.get_notification_topics(conf)] |
| 53 | |
| 54 | def process_notification(self, message): |
| 55 | if message['payload']: |
| 56 | resource_id = 'broadview_' + message["payload"]["asic-id"] |
| 57 | LOG.info('SRIKANTH: Received BroadView %(event_type)s notification: resource_id=%(resource_id)s' % {'event_type': message['event_type'], 'resource_id': resource_id}) |
| 58 | yield sample.Sample.from_notification( |
| 59 | name=message['event_type'], |
| 60 | type=sample.TYPE_GAUGE, |
| 61 | unit='bv-agent', |
| 62 | volume=message['payload']['value'], |
| 63 | user_id=None, |
| 64 | project_id='default_admin_tenant', |
| 65 | resource_id=resource_id, |
| 66 | message=message) |