Notifier

class 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
  • 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

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
  • publisher_id (str) – field in notifications sent, for example ‘compute.host1’

  • retry (int) – connection retries configuration (used by the messaging driver): None or -1 means to retry forever. 0 means no retry is attempted. N means attempt at most 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)
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.

Available Notifier Drivers

log

Publish notifications via Python logging infrastructure.

messaging

Send notifications using the 1.0 message format.

This driver sends notifications over the configured messaging transport, but without any message envelope (also known as message format 1.0).

This driver should only be used in cases where there are existing consumers deployed which do not support the 2.0 message format.

messagingv2

Send notifications using the 2.0 message format.

noop

Base driver for Notifications

routing

Base driver for Notifications

test

Store notifications in memory for test verification.