Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 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 | |
Srikanth Vavilapalli | 21d1475 | 2016-09-02 01:37:34 +0000 | [diff] [blame] | 17 | # |
| 18 | # Copyright 2012 New Dream Network, LLC (DreamHost) |
| 19 | # |
| 20 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 21 | # not use this file except in compliance with the License. You may obtain |
| 22 | # a copy of the License at |
| 23 | # |
| 24 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 25 | # |
| 26 | # Unless required by applicable law or agreed to in writing, software |
| 27 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 28 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 29 | # License for the specific language governing permissions and limitations |
| 30 | # under the License. |
| 31 | """Handler for producing network counter messages from Neutron notification |
| 32 | events. |
| 33 | |
| 34 | """ |
| 35 | |
| 36 | import oslo_messaging |
| 37 | from oslo_config import cfg |
| 38 | |
| 39 | from ceilometer.agent import plugin_base |
| 40 | from oslo_log import log |
| 41 | from ceilometer import sample |
| 42 | |
| 43 | OPTS = [ |
| 44 | cfg.StrOpt('broadview_control_exchange', |
| 45 | default='broadview_service', |
| 46 | help="Exchange name for Broadview notifications."), |
| 47 | ] |
| 48 | |
| 49 | cfg.CONF.register_opts(OPTS) |
| 50 | |
| 51 | LOG = log.getLogger(__name__) |
| 52 | |
| 53 | |
| 54 | class BroadViewNotificationBase(plugin_base.NotificationBase): |
| 55 | |
| 56 | resource_name = None |
Srikanth Vavilapalli | f6eda8f | 2016-09-09 13:43:51 -0400 | [diff] [blame] | 57 | event_types = ['broadview.bst.*','broadview.pt.*'] |
Srikanth Vavilapalli | 21d1475 | 2016-09-02 01:37:34 +0000 | [diff] [blame] | 58 | |
| 59 | def get_targets(self,conf): |
| 60 | """Return a sequence of oslo.messaging.Target |
| 61 | |
| 62 | This sequence is defining the exchange and topics to be connected for |
| 63 | this plugin. |
| 64 | """ |
| 65 | LOG.info("SRIKANTH: get_targets for BroadView Notification Listener") |
| 66 | return [oslo_messaging.Target(topic=topic, |
| 67 | exchange=conf.broadview_control_exchange) |
| 68 | for topic in self.get_notification_topics(conf)] |
| 69 | |
| 70 | def process_notification(self, message): |
| 71 | if message['payload']: |
| 72 | resource_id = 'broadview_' + message["payload"]["asic-id"] |
Srikanth Vavilapalli | f6eda8f | 2016-09-09 13:43:51 -0400 | [diff] [blame] | 73 | volume = 1 |
| 74 | if 'value' in message["payload"]: |
| 75 | if (not 'ignore-value' in message["payload"]) or (message["payload"]['ignore-value'] != 1): |
| 76 | volume = message["payload"]["value"] |
Srikanth Vavilapalli | 21d1475 | 2016-09-02 01:37:34 +0000 | [diff] [blame] | 77 | LOG.info('SRIKANTH: Received BroadView %(event_type)s notification: resource_id=%(resource_id)s' % {'event_type': message['event_type'], 'resource_id': resource_id}) |
| 78 | yield sample.Sample.from_notification( |
| 79 | name=message['event_type'], |
| 80 | type=sample.TYPE_GAUGE, |
| 81 | unit='bv-agent', |
Srikanth Vavilapalli | f6eda8f | 2016-09-09 13:43:51 -0400 | [diff] [blame] | 82 | volume=volume, |
Srikanth Vavilapalli | 21d1475 | 2016-09-02 01:37:34 +0000 | [diff] [blame] | 83 | user_id=None, |
| 84 | project_id='default_admin_tenant', |
| 85 | resource_id=resource_id, |
| 86 | message=message) |