blob: 2ab4c66ce161b64fe19693f371338e7d505f9a65 [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
Srikanth Vavilapalli21d14752016-09-02 01:37:34 +000017#
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
36import oslo_messaging
37from oslo_config import cfg
38
39from ceilometer.agent import plugin_base
40from oslo_log import log
41from ceilometer import sample
42
43OPTS = [
44 cfg.StrOpt('broadview_control_exchange',
45 default='broadview_service',
46 help="Exchange name for Broadview notifications."),
47]
48
49cfg.CONF.register_opts(OPTS)
50
51LOG = log.getLogger(__name__)
52
53
54class BroadViewNotificationBase(plugin_base.NotificationBase):
55
56 resource_name = None
Srikanth Vavilapallif6eda8f2016-09-09 13:43:51 -040057 event_types = ['broadview.bst.*','broadview.pt.*']
Srikanth Vavilapalli21d14752016-09-02 01:37:34 +000058
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 Vavilapallif6eda8f2016-09-09 13:43:51 -040073 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 Vavilapalli21d14752016-09-02 01:37:34 +000077 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 Vavilapallif6eda8f2016-09-09 13:43:51 -040082 volume=volume,
Srikanth Vavilapalli21d14752016-09-02 01:37:34 +000083 user_id=None,
84 project_id='default_admin_tenant',
85 resource_id=resource_id,
86 message=message)