mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 02:17:37 -02:30
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:
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# Python
|
# Python
|
||||||
import inspect
|
import inspect
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
@@ -31,6 +32,8 @@ __all__ = ['APIView', 'GenericAPIView', 'ListAPIView', 'SimpleListAPIView',
|
|||||||
'RetrieveAPIView', 'RetrieveUpdateAPIView',
|
'RetrieveAPIView', 'RetrieveUpdateAPIView',
|
||||||
'RetrieveDestroyAPIView', 'RetrieveUpdateDestroyAPIView']
|
'RetrieveDestroyAPIView', 'RetrieveUpdateDestroyAPIView']
|
||||||
|
|
||||||
|
logger = logging.getLogger('awx.api.generics')
|
||||||
|
|
||||||
def get_view_name(cls, suffix=None):
|
def get_view_name(cls, suffix=None):
|
||||||
'''
|
'''
|
||||||
Wrapper around REST framework get_view_name() to support get_name() method
|
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
|
ret['added_in_version'] = added_in_version
|
||||||
return ret
|
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):
|
class GenericAPIView(generics.GenericAPIView, APIView):
|
||||||
# Base class for all model-based views.
|
# Base class for all model-based views.
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ class JobTemplateCallbackPermission(ModelAccessPermission):
|
|||||||
# True to fall through to the next permission class.
|
# True to fall through to the next permission class.
|
||||||
if (request.user or request.auth) and request.method.lower() != 'post':
|
if (request.user or request.auth) and request.method.lower() != 'post':
|
||||||
return super(JobTemplateCallbackPermission, self).has_permission(request, view, obj)
|
return super(JobTemplateCallbackPermission, self).has_permission(request, view, obj)
|
||||||
|
|
||||||
# Require method to be POST, host_config_key to be specified and match
|
# Require method to be POST, host_config_key to be specified and match
|
||||||
# the requested job template, and require the job template to be
|
# the requested job template, and require the job template to be
|
||||||
# active in order to proceed.
|
# active in order to proceed.
|
||||||
|
|||||||
@@ -404,13 +404,27 @@ LOGGING = {
|
|||||||
'filters': ['require_debug_false'],
|
'filters': ['require_debug_false'],
|
||||||
'class': 'django.utils.log.AdminEmailHandler',
|
'class': 'django.utils.log.AdminEmailHandler',
|
||||||
},
|
},
|
||||||
|
'rotating_file': {
|
||||||
|
'level': 'WARNING',
|
||||||
|
'class':'logging.handlers.RotatingFileHandler',
|
||||||
|
'filters': ['require_debug_false'],
|
||||||
|
'filename': os.path.join(BASE_DIR, 'tower_warnings.log'),
|
||||||
|
'maxBytes': 1024*1024*5, # 5 MB
|
||||||
|
'backupCount': 5,
|
||||||
|
'formatter':'simple',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'django': {
|
'django': {
|
||||||
'handlers': ['console'],
|
'handlers': ['console'],
|
||||||
},
|
},
|
||||||
'django.request': {
|
'django.request': {
|
||||||
'handlers': ['mail_admins', 'console', 'file', 'syslog'],
|
'handlers': ['mail_admins', 'console', 'file', 'syslog', 'rotating_file'],
|
||||||
|
'level': 'WARNING',
|
||||||
|
'propagate': False,
|
||||||
|
},
|
||||||
|
'rest_framework.request': {
|
||||||
|
'handlers': ['mail_admins', 'console', 'file', 'syslog', 'rotating_file'],
|
||||||
'level': 'WARNING',
|
'level': 'WARNING',
|
||||||
'propagate': False,
|
'propagate': False,
|
||||||
},
|
},
|
||||||
@@ -418,7 +432,7 @@ LOGGING = {
|
|||||||
'handlers': ['console'],
|
'handlers': ['console'],
|
||||||
},
|
},
|
||||||
'awx': {
|
'awx': {
|
||||||
'handlers': ['console', 'file', 'syslog'],
|
'handlers': ['console', 'file', 'syslog', 'rotating_file'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'awx.main.access': {
|
'awx.main.access': {
|
||||||
|
|||||||
Reference in New Issue
Block a user