blob: bfe8dd4884de57a212caab406731f9f3cbfdea8d [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
rdudyalab086cf32016-08-11 00:07:45 -040017#
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('voltservice_control_exchange',
45 default='voltlistener',
46 help="Exchange name for VOLT notifications."),
47]
48
49cfg.CONF.register_opts(OPTS)
50
51LOG = log.getLogger(__name__)
52
53
54class VOLTNotificationBase(plugin_base.NotificationBase):
55
56 resource_name = None
57
58 def get_targets(self,conf):
59 """Return a sequence of oslo.messaging.Target
60
61 This sequence is defining the exchange and topics to be connected for
62 this plugin.
63 """
64 LOG.info("SRIKANTH: get_targets for VOLT Notification Listener")
65 return [oslo_messaging.Target(topic=topic,
66 exchange=conf.voltservice_control_exchange)
67 for topic in self.get_notification_topics(conf)]
68
69class VOLTDeviceNotification(VOLTNotificationBase):
70 resource_name = 'volt.device'
71 event_types = ['volt.device','volt.device.disconnect']
72
73 def process_notification(self, message):
74 LOG.info('SRIKANTH: Received VOLT notification')
75 yield sample.Sample.from_notification(
76 name=message['event_type'],
77 type=sample.TYPE_GAUGE,
78 unit='olt',
79 volume=1,
80 user_id=message['payload']['user_id'],
81 project_id=message['payload']['project_id'],
82 resource_id=message['payload']['id'],
83 message=message)
84
85class VOLTDeviceSubscriberNotification(VOLTNotificationBase):
86 resource_name = 'volt.device.subscriber'
87 event_types = ['volt.device.subscriber','volt.device.subscriber.unregister']
88
89 def process_notification(self, message):
90 LOG.info('SRIKANTH: Received VOLT notification')
91 resource_id = message['payload']['id'] + '-' + message['payload']['subscriber_id']
92 yield sample.Sample.from_notification(
93 name=message['event_type'],
94 type=sample.TYPE_GAUGE,
95 unit='subscriber',
96 volume=1,
97 user_id=message['payload']['user_id'],
98 project_id=message['payload']['project_id'],
99 resource_id=resource_id,
100 message=message)
101
102