summaryrefslogtreecommitdiffstats
path: root/nova/notifications.py
diff options
context:
space:
mode:
authorSandyWalsh <sandy.walsh@rackspace.com>2012-09-19 11:19:37 -0300
committerSandyWalsh <sandy.walsh@rackspace.com>2012-09-19 16:10:04 -0300
commit4de976ccf8f27c152f89aecc7ded2c2cd9d0a710 (patch)
treead36bcfc1df9204bd73b600d17941f1bc2a20a29 /nova/notifications.py
parenta484bfea8ff3f274bb71be11ff387aa671c1e798 (diff)
downloadnova-4de976ccf8f27c152f89aecc7ded2c2cd9d0a710.tar.gz
nova-4de976ccf8f27c152f89aecc7ded2c2cd9d0a710.tar.xz
nova-4de976ccf8f27c152f89aecc7ded2c2cd9d0a710.zip
Send api.fault notification on API service faults.
Exceptions caught by the API middleware will now send "api.fault" notifications indicating the offending URL and the underlying exception. The allows the billing/usage systems to track requests end-to-end without having to monitor log files. Disabled by default. Enable with --notify_api_faults Change-Id: Ied2783259413ba12d686b44b33e0707645e51afb
Diffstat (limited to 'nova/notifications.py')
-rw-r--r--nova/notifications.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/nova/notifications.py b/nova/notifications.py
index 73b318c5c..2df5b95f7 100644
--- a/nova/notifications.py
+++ b/nova/notifications.py
@@ -45,9 +45,29 @@ notify_any_opt = cfg.BoolOpt('notify_on_any_change', default=False,
'state changes. Valid values are False for no notifications, '
'True for notifications on any instance changes.')
+notify_api_faults = cfg.BoolOpt('notify_api_faults', default=False,
+ help='If set, send api.fault notifications on caught exceptions '
+ 'in the API service.')
+
+
FLAGS = flags.FLAGS
FLAGS.register_opt(notify_state_opt)
FLAGS.register_opt(notify_any_opt)
+FLAGS.register_opt(notify_api_faults)
+
+
+def send_api_fault(url, status, exception):
+ """Send an api.fault notification."""
+
+ if not FLAGS.notify_api_faults:
+ return
+
+ payload = {'url': url, 'exception': str(exception), 'status': status}
+
+ publisher_id = notifier_api.publisher_id("api")
+
+ notifier_api.notify(None, publisher_id, 'api.fault', notifier_api.ERROR,
+ payload)
def send_update(context, old_instance, new_instance, service=None, host=None):