Notifier

class oslo.messaging.Notifier(transport, publisher_id=None, driver=None, topic=None, serializer=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': str(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 = notifier.Notifier(get_transport(CONF), ‘compute’)

and notifications are sent via drivers chosen with the notification_driver config option and on the topics consen with the notification_topics config option.

Alternatively, a Notifier object can be instantiated with a specific driver or topic:

notifier = notifier.Notifier(RPC_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, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
critical(ctxt, event_type, payload)

Send a notification at critical level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
debug(ctxt, event_type, payload)

Send a notification at debug level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
error(ctxt, event_type, payload)

Send a notification at error level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
info(ctxt, event_type, payload)

Send a notification at info level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
prepare(publisher_id=<object object at 0x25941f0>)

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, e.g. ‘compute.host1’
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, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
warn(ctxt, event_type, payload)

Send a notification at warning level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
warning(ctxt, event_type, payload)

Send a notification at warning level.

Parameters:
  • ctxt (dict) – a request context dict
  • event_type (str) – describes the event, e.g. ‘compute.create_instance’
  • payload (dict) – the notification payload
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=('qpid:///')
CONF = <oslo.config.cfg.ConfigOpts object at 0x2b1ea50>

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.PublishErrorsHandler(*args, **kwargs)

Previous topic

RPC Client

Next topic

Notification Listener

This Page