Notifier¶
-
class
oslo_messaging.
Notifier
(*args, **kwargs)¶ 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', topic='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: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
critical
(ctxt, event_type, payload)¶ Send a notification at critical level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
debug
(ctxt, event_type, payload)¶ Send a notification at debug level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
error
(ctxt, event_type, payload)¶ Send a notification at error level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
info
(ctxt, event_type, payload)¶ Send a notification at info level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
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: - publisher_id (str) – field in notifications sent, for example ‘compute.host1’
- retry (int) – an connection retries configuration None or -1 means to retry forever 0 means no retry N means N retries
-
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: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
warn
(ctxt, event_type, payload)¶ Send a notification at warning level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
warning
(ctxt, event_type, payload)¶ Send a notification at warning level.
Parameters: - ctxt (dict) – a request context dict
- event_type (str) – describes the event, for example ‘compute.create_instance’
- payload (dict) – the notification payload
Raises: MessageDeliveryFailure
-
class
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.
-
-
class
oslo_messaging.
LoggingErrorNotificationHandler
(*args, **kwargs)¶