mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
enable Logstash auth and prepare for handler for multiple auth types
This commit is contained in:
@@ -23,6 +23,9 @@ from requests_futures.sessions import FuturesSession
|
|||||||
# Logstash
|
# Logstash
|
||||||
from logstash import formatter
|
from logstash import formatter
|
||||||
|
|
||||||
|
# custom
|
||||||
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
|
|
||||||
ENABLED_LOGS = ['ansible']
|
ENABLED_LOGS = ['ansible']
|
||||||
|
|
||||||
@@ -61,13 +64,16 @@ def bg_cb(sess, resp):
|
|||||||
|
|
||||||
# add port for a generic handler
|
# add port for a generic handler
|
||||||
class HTTPSHandler(logging.Handler):
|
class HTTPSHandler(logging.Handler):
|
||||||
def __init__(self, host, port=80, message_type='logstash', fqdn=False):
|
def __init__(self, host, fqdn=False, **kwargs):
|
||||||
super(HTTPSHandler, self).__init__()
|
super(HTTPSHandler, self).__init__()
|
||||||
self.host_saved = host
|
self.host_saved = host
|
||||||
self.port = port
|
|
||||||
# self.port = port
|
|
||||||
self.message_type = message_type
|
|
||||||
self.fqdn = fqdn
|
self.fqdn = fqdn
|
||||||
|
for fd in ['port', 'message_type', 'username', 'password']:
|
||||||
|
if fd in kwargs:
|
||||||
|
attr_name = fd
|
||||||
|
if fd == 'username':
|
||||||
|
attr_name = 'user'
|
||||||
|
setattr(self, attr_name, kwargs[fd])
|
||||||
|
|
||||||
def get_full_message(self, record):
|
def get_full_message(self, record):
|
||||||
if record.exc_info:
|
if record.exc_info:
|
||||||
@@ -75,6 +81,19 @@ class HTTPSHandler(logging.Handler):
|
|||||||
else:
|
else:
|
||||||
return record.getMessage()
|
return record.getMessage()
|
||||||
|
|
||||||
|
def add_auth_information(self, kwargs):
|
||||||
|
if self.message_type == 'logstash':
|
||||||
|
if not self.user:
|
||||||
|
# Logstash authentication not enabled
|
||||||
|
return kwargs
|
||||||
|
logstash_auth = HTTPBasicAuth(self.user, self.password)
|
||||||
|
kwargs['auth'] = logstash_auth
|
||||||
|
elif self.message_type == 'splunk':
|
||||||
|
auth_header = "Splunk %s" % self.token
|
||||||
|
headers = dict(Authorization=auth_header)
|
||||||
|
kwargs['headers'] = headers
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
try:
|
try:
|
||||||
payload = self.format(record)
|
payload = self.format(record)
|
||||||
@@ -94,7 +113,9 @@ class HTTPSHandler(logging.Handler):
|
|||||||
host = 'http://%s' % self.host_saved
|
host = 'http://%s' % self.host_saved
|
||||||
if self.port != 80:
|
if self.port != 80:
|
||||||
host = '%s:%s' % (host, str(self.port))
|
host = '%s:%s' % (host, str(self.port))
|
||||||
session.post(host, data=payload, background_callback=bg_cb)
|
bare_kwargs = dict(data=payload, background_callback=bg_cb)
|
||||||
|
kwargs = self.add_auth_information(bare_kwargs)
|
||||||
|
session.post(host, **kwargs)
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -892,7 +892,9 @@ LOGGING = {
|
|||||||
'message_type': 'logstash',
|
'message_type': 'logstash',
|
||||||
'fqdn': True,
|
'fqdn': True,
|
||||||
# 'tags': ['tower'],
|
# 'tags': ['tower'],
|
||||||
'formatter': 'json'
|
'formatter': 'json',
|
||||||
|
'username': 'awx_logger',
|
||||||
|
'password': 'workflows',
|
||||||
},
|
},
|
||||||
'mail_admins': {
|
'mail_admins': {
|
||||||
'level': 'ERROR',
|
'level': 'ERROR',
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
input {
|
input {
|
||||||
http {
|
http {
|
||||||
port => 8085
|
port => 8085
|
||||||
|
user => awx_logger
|
||||||
|
password => "workflows"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user