Smarter log aggregator host name generation.

This commit is contained in:
Aaron Tan
2017-03-17 17:54:29 -04:00
parent fe78d86c4a
commit f69c2569d6

View File

@@ -6,6 +6,7 @@ import logging
import json import json
import requests import requests
import time import time
import re
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from copy import copy from copy import copy
@@ -118,10 +119,18 @@ 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'): # Force using http(s) protocol
host = 'http://%s' % self.host if re.match(r'https?://', host) is None:
if self.port != 80 and self.port is not None: if re.match(r'[a-zA-Z]+://', host) is None:
host = '%s:%s' % (host, str(self.port)) host = 'http://%s' % self.host
else:
host = re.sub(r'[a-zA-Z]+://', r'http://', host, count=1)
# Insert self.port if its special and port number not given in host
if (self.port != 80 and self.port is not None and
re.match(r'https?://[^:/]+:[0-9]+', host) is None):
host = re.sub(r'https?://[^/]+',
lambda m: '%s:%s' % (m.group(0), str(self.port),
host, count=1)
return host return host
def get_post_kwargs(self, payload_input): def get_post_kwargs(self, payload_input):