summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCerberus <matt.dietz@rackspace.com>2011-05-09 16:52:52 -0500
committerCerberus <matt.dietz@rackspace.com>2011-05-09 16:52:52 -0500
commit4364c3e4103e41fcb8bb0c2af764c37c1ff4afab (patch)
treeedb7f751534fe4a4deeb0a1515442e5912078e02
parentc03e9805328afe1d03fa65ac93d2b91ba04c229e (diff)
Better message format description
-rw-r--r--nova/notifier/__init__.py40
-rw-r--r--nova/notifier/rabbit_notifier.py6
2 files changed, 40 insertions, 6 deletions
diff --git a/nova/notifier/__init__.py b/nova/notifier/__init__.py
index 8053b8a0a..e6a4a0165 100644
--- a/nova/notifier/__init__.py
+++ b/nova/notifier/__init__.py
@@ -13,12 +13,46 @@
# License for the specific language governing permissions and limitations
# under the License.
+import datetime
+import json
+
from nova import flags
from nova import utils
FLAGS = flags.FLAGS
-def notify(event_name, model):
- """Sends a notification using the specified driver"""
+flags.DEFINE_string('default_notification_level', 'info',
+ 'Default notification level for outgoing notifications')
+
+WARN = 'WARN'
+INFO = 'INFO'
+ERROR = 'ERROR'
+CRITICAL = 'CRITICAL'
+DEBUG = 'DEBUG'
+
+log_levels = (DEBUG, WARN, INFO, ERROR, CRITICAL)
+
+def notify(event_name, publisher_id, event_type, priority, payload):
+ """
+ Sends a notification using the specified driver
+
+ Message format is as follows:
+
+ publisher_id - the source worker_type.host of the message
+ timestamp - the GMT timestamp the notification was sent at
+ event_type - the literal type of event (ex. Instance Creation)
+ priority - patterned after the enumeration of Python logging levels in
+ the set (DEBUG, WARN, INFO, ERROR, CRITICAL)
+ payload - A python dictionary of attributes
+
+ The payload will be constructed as a dictionary of the above attributes,
+ and converted into a JSON dump, which will then be sent via the transport
+ mechanism defined by the driver.
+ """
driver = utils.import_class(FLAGS.notification_driver)()
- driver.notify(event_name, model)
+ message = dict(publisher_id=publisher_id,
+ event_type=event_type,
+ priority=priority,
+ payload=payload,
+ time=datetime.datetime.utcnow())
+ driver.notify(json.dumps(message))
diff --git a/nova/notifier/rabbit_notifier.py b/nova/notifier/rabbit_notifier.py
index 33cf06566..e4bd85398 100644
--- a/nova/notifier/rabbit_notifier.py
+++ b/nova/notifier/rabbit_notifier.py
@@ -25,13 +25,13 @@ FLAGS = flags.FLAGS
flags.DEFINE_string('notification_topic', 'notifications',
'RabbitMQ topic used for Nova notifications')
+
class RabbitNotifier(object):
"""Sends notifications to a specific RabbitMQ server and topic"""
pass
- def notify(self, event_name, model):
+ def notify(self, payload):
"""Sends a notification to the RabbitMQ"""
context = nova.context.get_admin_context()
topic = FLAGS.notification_topic
- msg = { 'event_name': event_name, 'model': model.__dict__ }
- rpc.cast(context, topic, json.dumps(msg))
+ rpc.cast(context, topic, msg)