Add a specific tower warnings file in the tower home directory.

Configure the api viewer to emit warnings for 4XX and 5XX status codes
into that file.  Configure it for use on a production system.  Closes AC-685
This commit is contained in:
Matthew Jones
2014-04-04 16:48:56 -04:00
parent f56b716b8f
commit e197bfeb01
3 changed files with 25 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
# Python
import inspect
import logging
import json
# Django
@@ -31,6 +32,8 @@ __all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView',
'RetrieveAPIView', 'RetrieveUpdateAPIView',
'RetrieveDestroyAPIView', 'RetrieveUpdateDestroyAPIView']
logger = logging.getLogger('awx.api.generics')
def get_view_name(cls, suffix=None):
'''
Wrapper around REST framework get_view_name() to support get_name() method
@@ -131,6 +134,11 @@ class APIView(views.APIView):
ret['added_in_version'] = added_in_version
return ret
def finalize_response(self, request, response, *args, **kwargs):
if response.status_code >= 400:
logger.warn("status %s received by user %s attempting to access %s" % (response.status_code, request.user, request.path))
return super(APIView, self).finalize_response(request, response, *args, **kwargs)
class GenericAPIView(generics.GenericAPIView, APIView):
# Base class for all model-based views.