1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-28 02:25:27 +03:00

Merge pull request #5792 from jangsutsr/5628_smarter_log_aggregator_host_name_generation

Smarter log aggregator host name generation
This commit is contained in:
Aaron Tan 2017-03-24 11:46:46 -04:00 committed by GitHub
commit 7ba79c1027
2 changed files with 27 additions and 5 deletions

View File

@ -107,7 +107,17 @@ def test_https_logging_handler_splunk_auth_info():
('http://localhost', None, 'http://localhost'), ('http://localhost', None, 'http://localhost'),
('http://localhost', 80, 'http://localhost'), ('http://localhost', 80, 'http://localhost'),
('http://localhost', 8080, 'http://localhost:8080'), ('http://localhost', 8080, 'http://localhost:8080'),
('https://localhost', 443, 'https://localhost:443') ('https://localhost', 443, 'https://localhost:443'),
('ftp://localhost', 443, 'ftp://localhost:443'),
('https://localhost:550', 443, 'https://localhost:550'),
('https://localhost:yoho/foobar', 443, 'https://localhost:443/foobar'),
('https://localhost:yoho/foobar', None, 'https://localhost:yoho/foobar'),
('http://splunk.server:8088/services/collector/event', 80,
'http://splunk.server:8088/services/collector/event'),
('http://splunk.server/services/collector/event', 80,
'http://splunk.server/services/collector/event'),
('http://splunk.server/services/collector/event', 8088,
'http://splunk.server:8088/services/collector/event'),
]) ])
def test_https_logging_handler_http_host_format(host, port, normalized): def test_https_logging_handler_http_host_format(host, port, normalized):
handler = HTTPSHandler(host=host, port=port) handler = HTTPSHandler(host=host, port=port)

View File

@ -6,6 +6,7 @@ import logging
import json import json
import requests import requests
import time import time
import urlparse
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from copy import copy from copy import copy
@ -118,10 +119,21 @@ class BaseHTTPSHandler(logging.Handler):
def get_http_host(self): def get_http_host(self):
host = self.host or '' host = self.host or ''
if not host.startswith('http'): # urlparse requires scheme to be provided, default to use http if
host = 'http://%s' % self.host # missing
if self.port != 80 and self.port is not None: if not urlparse.urlsplit(host).scheme:
host = '%s:%s' % (host, str(self.port)) host = 'http://%s' % host
parsed = urlparse.urlsplit(host)
# Insert self.port if its special and port number is either not
# given in host or given as non-numerical
try:
port = parsed.port or self.port
except ValueError:
port = self.port
if port not in (80, None):
new_netloc = '%s:%s' % (parsed.hostname, port)
return urlparse.urlunsplit((parsed.scheme, new_netloc, parsed.path,
parsed.query, parsed.fragment))
return host return host
def get_post_kwargs(self, payload_input): def get_post_kwargs(self, payload_input):