blob: 6c09c75623ad78b56027eb0ec8c937175763e1a2 [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('openstack_infra_service_control_exchange',
45 default='openstack_infra',
46 help="Exchange name for INFRA notifications."),
47]
48
49cfg.CONF.register_opts(OPTS)
50
51LOG = log.getLogger(__name__)
52
53
54class OPENSTACK_INFRANotificationBase(plugin_base.NotificationBase):
55
56 resource_name = None
57
58 def get_targets(self,conf):
59 """Return a sequence of oslo.messaging.Target
60 This sequence is defining the exchange and topics to be connected for
61 this plugin.
62 """
63 LOG.info("get_targets for OPENSTACK INFRA Notification Listener")
64 return [oslo_messaging.Target(topic=topic,
65 exchange=conf.openstack_infra_service_control_exchange)
66 for topic in self.get_notification_topics(conf)]
67
68class OPENSTACK_INFRANotification(OPENSTACK_INFRANotificationBase):
69
70 resource_name = None
71 event_types = ['infra$']
72
73 def process_notification(self, message):
74 LOG.info('Received OPENSTACK INFRA notification: resource_id =%(resource_id)s' % {'resource_id': message['payload']['resource_id']})
75 yield sample.Sample.from_notification(
76 name=message['payload']['counter_name'],
77 type=message['payload']['counter_type'],
78 unit=message['payload']['counter_unit'],
79 volume=message['payload']['counter_volume'],
80 user_id=message['payload']['user_id'],
81 project_id=message['payload']['project_id'],
82 resource_id=message['payload']['resource_id'],
83 message=message)