Better message format description

This commit is contained in:
Cerberus
2011-05-09 16:52:52 -05:00
parent 386e5fb399
commit 56c9bf5fcd
2 changed files with 40 additions and 6 deletions

View File

@@ -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))

View File

@@ -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)