mirror of
https://github.com/ansible/awx.git
synced 2026-03-22 11:25:08 -02:30
Fix Logging settings "Test" button functionality
This commit is contained in:
@@ -1 +1,2 @@
|
|||||||
# Test Logging Configuration
|
# Test Logging Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
import collections
|
import collections
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import socket
|
||||||
|
import os
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -12,7 +15,7 @@ from django.http import Http404
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# Django REST Framework
|
# Django REST Framework
|
||||||
from rest_framework.exceptions import PermissionDenied, ValidationError
|
from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@@ -161,8 +164,41 @@ class SettingLoggingTest(GenericAPIView):
|
|||||||
filter_backends = []
|
filter_backends = []
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
logging.getLogger('awx').info('AWX Connection Test')
|
# Send test message to configured logger based on db settings
|
||||||
return Response(status=status.HTTP_202_ACCEPTED)
|
logging.getLogger('awx').error('AWX Connection Test Message')
|
||||||
|
|
||||||
|
hostname = getattr(settings, 'LOG_AGGREGATOR_HOST', None)
|
||||||
|
protocol = getattr(settings, 'LOG_AGGREGATOR_PROTOCOL', None)
|
||||||
|
|
||||||
|
# Check if host is reacheable
|
||||||
|
host = urlparse(hostname).netloc
|
||||||
|
response = os.system("ping -c 1 " + host)
|
||||||
|
if response != 0:
|
||||||
|
return Response({'error': 'The host is not available'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
# Check to ensure port is open at host
|
||||||
|
if protocol in ['udp', 'tcp']:
|
||||||
|
port = getattr(settings, 'LOG_AGGREGATOR_PORT', None)
|
||||||
|
# Error if port is not set when using UDP/TCP
|
||||||
|
if not port:
|
||||||
|
return Response({'error': 'Port required for ' + protocol}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
else:
|
||||||
|
return Response(status=status.HTTP_202_ACCEPTED)
|
||||||
|
|
||||||
|
# Error if logging is not enabled
|
||||||
|
enabled = getattr(settings, 'LOG_AGGREGATOR_ENABLED', False)
|
||||||
|
if not enabled:
|
||||||
|
return Response({'error': 'Logging not enabled'}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
|
try:
|
||||||
|
s.settimeout(.5)
|
||||||
|
s.connect((hostname, int(port)))
|
||||||
|
s.shutdown(2)
|
||||||
|
s.close()
|
||||||
|
return Response(status=status.HTTP_202_ACCEPTED)
|
||||||
|
except Exception as e:
|
||||||
|
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
# Create view functions for all of the class-based views to simplify inclusion
|
# Create view functions for all of the class-based views to simplify inclusion
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ from awx.main.utils import (get_ssh_version, update_scm_url,
|
|||||||
ignore_inventory_group_removal, extract_ansible_vars, schedule_task_manager,
|
ignore_inventory_group_removal, extract_ansible_vars, schedule_task_manager,
|
||||||
get_awx_version)
|
get_awx_version)
|
||||||
from awx.main.utils.ansible import read_ansible_config
|
from awx.main.utils.ansible import read_ansible_config
|
||||||
from awx.main.utils.common import get_ansible_version, _get_ansible_version, get_custom_venv_choices
|
from awx.main.utils.common import _get_ansible_version, get_custom_venv_choices
|
||||||
from awx.main.utils.external_logging import reconfigure_rsyslog
|
from awx.main.utils.external_logging import reconfigure_rsyslog
|
||||||
from awx.main.utils.safe_yaml import safe_dump, sanitize_jinja
|
from awx.main.utils.safe_yaml import safe_dump, sanitize_jinja
|
||||||
from awx.main.utils.reload import stop_local_services
|
from awx.main.utils.reload import stop_local_services
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ import subprocess
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Django
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
logger = logging.getLogger('awx.main.utils.reload')
|
logger = logging.getLogger('awx.main.utils.reload')
|
||||||
|
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ export default [
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(({ data, status }) => {
|
.catch(({ data, status }) => {
|
||||||
if (status === 500) {
|
if (status === 400 || status == 500) {
|
||||||
ngToast.danger({
|
ngToast.danger({
|
||||||
content: '<i class="fa fa-exclamation-triangle Toast-successIcon"></i>' +
|
content: '<i class="fa fa-exclamation-triangle Toast-successIcon"></i>' +
|
||||||
i18n._('Log aggregator test failed. <br> Detail: ') + $filter('sanitize')(data.error),
|
i18n._('Log aggregator test failed. <br> Detail: ') + $filter('sanitize')(data.error),
|
||||||
|
|||||||
@@ -72,7 +72,11 @@ stdout_logfile=/dev/fd/1
|
|||||||
stdout_logfile_maxbytes=0
|
stdout_logfile_maxbytes=0
|
||||||
|
|
||||||
[program:awx-rsyslogd]
|
[program:awx-rsyslogd]
|
||||||
|
<<<<<<< HEAD
|
||||||
command = rsyslogd -n -i /var/run/rsyslog/rsyslog.pid -f /var/lib/awx/rsyslog/rsyslog.conf
|
command = rsyslogd -n -i /var/run/rsyslog/rsyslog.pid -f /var/lib/awx/rsyslog/rsyslog.conf
|
||||||
|
=======
|
||||||
|
command = rsyslogd -n -i /var/run/tower/sockets/rsyslog.pid -f /var/lib/awx/rsyslog/rsyslog.conf
|
||||||
|
>>>>>>> 3a8bd7c40... Fix Logging settings "Test" button functionality
|
||||||
autostart = true
|
autostart = true
|
||||||
autorestart = true
|
autorestart = true
|
||||||
stopwaitsecs = 1
|
stopwaitsecs = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user