oslo_messaging.
Notifier
(transport, publisher_id=None, driver=None, serializer=None, retry=None, topics=None)¶Send notification messages.
The Notifier class is used for sending notification messages over a messaging transport or other means.
Notification messages follow the following format:
{'message_id': six.text_type(uuid.uuid4()),
'publisher_id': 'compute.host1',
'timestamp': timeutils.utcnow(),
'priority': 'WARN',
'event_type': 'compute.create_instance',
'payload': {'instance_id': 12, ... }}
A Notifier object can be instantiated with a transport object and a publisher ID:
- notifier = messaging.Notifier(get_notification_transport(CONF),
- ‘compute’)
and notifications are sent via drivers chosen with the driver config option and on the topics chosen with the topics config option in [oslo_messaging_notifications] section.
Alternatively, a Notifier object can be instantiated with a specific driver or topic:
transport = notifier.get_notification_transport(CONF)
notifier = notifier.Notifier(transport,
'compute.host',
driver='messaging',
topics=['notifications'])
Notifier objects are relatively expensive to instantiate (mostly the cost of loading notification drivers), so it is possible to specialize a given Notifier object with a different publisher id using the prepare() method:
notifier = notifier.prepare(publisher_id='compute')
notifier.info(ctxt, event_type, payload)
audit
(ctxt, event_type, payload)¶Send a notification at audit level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
critical
(ctxt, event_type, payload)¶Send a notification at critical level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
debug
(ctxt, event_type, payload)¶Send a notification at debug level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
error
(ctxt, event_type, payload)¶Send a notification at error level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
info
(ctxt, event_type, payload)¶Send a notification at info level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
is_enabled
()¶Check if the notifier will emit notifications anywhere.
Returns: | false if the driver of the notifier is set only to noop, true otherwise |
---|
prepare
(publisher_id=<object object>, retry=<object object>)¶Return a specialized Notifier instance.
Returns a new Notifier instance with the supplied publisher_id. Allows sending notifications from multiple publisher_ids without the overhead of notification driver loading.
Parameters: |
|
---|
sample
(ctxt, event_type, payload)¶Send a notification at sample level.
Sample notifications are for high-frequency events that typically contain small payloads. eg: “CPU = 70%”
Not all drivers support the sample level (log, for example) so these could be dropped.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
warn
(ctxt, event_type, payload)¶Send a notification at warning level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
warning
(ctxt, event_type, payload)¶Send a notification at warning level.
Parameters: |
|
---|---|
Raises: | MessageDeliveryFailure |
oslo_messaging.
LoggingNotificationHandler
(url, publisher_id=None, driver=None, topic=None, serializer=None)¶Handler for logging to the messaging notification system.
Each time the application logs a message using the logging
module, it will be sent as a notification. The severity used for the
notification will be the same as the one used for the log record.
This can be used into a Python logging configuration this way:
[handler_notifier]
class=oslo_messaging.LoggingNotificationHandler
level=ERROR
args=('rabbit:///')
CONF
= <oslo_config.cfg.ConfigOpts object>¶Default configuration object used, subclass this class if you want to use another one.
emit
(record)¶Emit the log record to the messaging notification system.
Parameters: | record – A log record to emit. |
---|
oslo_messaging.
LoggingErrorNotificationHandler
(*args, **kwargs)¶emit
(record)¶Do whatever it takes to actually log the specified logging record.
This version is intended to be implemented by subclasses and so raises a NotImplementedError.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.