Enable innocuous but valid config for rsyslog if disabled

This commit is contained in:
Christian Adams
2020-04-07 18:39:36 -04:00
parent e740340793
commit 470159b4d7
3 changed files with 18 additions and 8 deletions
+6 -2
View File
@@ -166,7 +166,7 @@ class SettingLoggingTest(GenericAPIView):
# 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)
return Response({'error': 'Logging not enabled'}, status=status.HTTP_409_CONFLICT)
# Send test message to configured logger based on db settings
logging.getLogger('awx').error('AWX Connection Test Message')
@@ -183,7 +183,11 @@ class SettingLoggingTest(GenericAPIView):
else:
# if http/https by this point, domain is reacheable
return Response(status=status.HTTP_202_ACCEPTED)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if protocol is 'udp':
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
else:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.settimeout(.5)
s.connect((hostname, int(port)))
+11 -5
View File
@@ -26,8 +26,10 @@ def construct_rsyslog_conf_template(settings=settings):
port = parsed.port
except ValueError:
port = settings.LOG_AGGREGATOR_PORT
parts.extend([
'$WorkDirectory /var/lib/awx/rsyslog',
'$IncludeConfig /etc/rsyslog.d/*.conf',
'$ModLoad imuxsock',
'input(type="imuxsock" Socket="' + settings.LOGGING['handlers']['external_logger']['address'] + '" unlink="on")',
'template(name="awx" type="string" string="%msg%")',
])
@@ -63,10 +65,14 @@ def construct_rsyslog_conf_template(settings=settings):
parts.append(
f'action(type="omfwd" target="{host}" port="{port}" protocol="{protocol}" action.resumeRetryCount="-1" template="awx")' # noqa
)
parts.extend([
'$WorkDirectory /var/lib/awx/rsyslog',
'$IncludeConfig /etc/rsyslog.d/*.conf'
])
else:
# If logging is disabled, add a valid config and discard all messages
parts = [
'$WorkDirectory /var/lib/awx/rsyslog',
'$IncludeConfig /etc/rsyslog.d/*.conf',
'*.* stop'
f'action(type="omfwd" target="localhost" port="9000" protocol="udp")'
]
tmpl = '\n'.join(parts)
return tmpl