~ubuntu-branches/ubuntu/trusty/ceilometer/trusty-proposed

« back to all changes in this revision

Viewing changes to ceilometer/openstack/common/notifier/proxy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2014-01-23 15:08:11 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140123150811-1zaismsuyh1hcl8y
Tags: 2014.1~b2-0ubuntu1
[ James Page ]
* d/control: Add python-jsonpath-rw to BD's.
* d/p/fix-setup-requirements.patch: Bump WebOb to support < 1.4.
 (LP: #1261101)

[ Chuck Short ]
* New upstream version.
* debian/control, debian/ceilometer-common.install: Split out
  ceilometer-alarm-evaluator and ceilometer-alarm-notifier into their
  own packages. (LP: #1250002)
* debian/ceilometer-agent-central.logrotate,
  debian/ceilometer-agent-compute.logrotate,
  debian/ceilometer-api.logrotate,
  debian/ceilometer-collector.logrotate: Add logrotate files, 
  thanks to Ahmed Rahal. (LP: #1224223)
* Fix typos in upstart files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2013 Red Hat, Inc.
 
2
#
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
 
 
15
"""
 
16
A temporary helper which emulates ceilometer.messaging.Notifier.
 
17
 
 
18
This helper method allows us to do the tedious porting to the new Notifier API
 
19
as a standalone commit so that the commit which switches us to ceilometer.messaging
 
20
is smaller and easier to review. This file will be removed as part of that
 
21
commit.
 
22
"""
 
23
 
 
24
from oslo.config import cfg
 
25
 
 
26
from ceilometer.openstack.common.notifier import api as notifier_api
 
27
 
 
28
CONF = cfg.CONF
 
29
 
 
30
 
 
31
class Notifier(object):
 
32
 
 
33
    def __init__(self, publisher_id):
 
34
        super(Notifier, self).__init__()
 
35
        self.publisher_id = publisher_id
 
36
 
 
37
    _marker = object()
 
38
 
 
39
    def prepare(self, publisher_id=_marker):
 
40
        ret = self.__class__(self.publisher_id)
 
41
        if publisher_id is not self._marker:
 
42
            ret.publisher_id = publisher_id
 
43
        return ret
 
44
 
 
45
    def _notify(self, ctxt, event_type, payload, priority):
 
46
        notifier_api.notify(ctxt,
 
47
                            self.publisher_id,
 
48
                            event_type,
 
49
                            priority,
 
50
                            payload)
 
51
 
 
52
    def audit(self, ctxt, event_type, payload):
 
53
        # No audit in old notifier.
 
54
        self._notify(ctxt, event_type, payload, 'INFO')
 
55
 
 
56
    def debug(self, ctxt, event_type, payload):
 
57
        self._notify(ctxt, event_type, payload, 'DEBUG')
 
58
 
 
59
    def info(self, ctxt, event_type, payload):
 
60
        self._notify(ctxt, event_type, payload, 'INFO')
 
61
 
 
62
    def warn(self, ctxt, event_type, payload):
 
63
        self._notify(ctxt, event_type, payload, 'WARN')
 
64
 
 
65
    warning = warn
 
66
 
 
67
    def error(self, ctxt, event_type, payload):
 
68
        self._notify(ctxt, event_type, payload, 'ERROR')
 
69
 
 
70
    def critical(self, ctxt, event_type, payload):
 
71
        self._notify(ctxt, event_type, payload, 'CRITICAL')
 
72
 
 
73
 
 
74
def get_notifier(service=None, host=None, publisher_id=None):
 
75
    if not publisher_id:
 
76
        publisher_id = "%s.%s" % (service, host or CONF.host)
 
77
    return Notifier(publisher_id)