Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite redirect loop with httpd collector, support HTTPS #567

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/collectors/httpd/httpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def get_default_config_help(self):
'urls': "Urls to server-status in auto format, comma seperated," +
" Format 'nickname http://host:port/server-status?auto, " +
", nickname http://host:port/server-status?auto, etc'",
'redirects': "The maximum number of redirect requests to follow.",
})
return config_help

Expand All @@ -53,8 +54,9 @@ def get_default_config(self):
"""
config = super(HttpdCollector, self).get_default_config()
config.update({
'path': 'httpd',
'urls': ['localhost http://localhost:8080/server-status?auto']
'path': 'httpd',
'urls': ['localhost http://localhost:8080/server-status?auto'],
'redirects': 5,
})
return config

Expand All @@ -63,26 +65,21 @@ def collect(self):
url = self.urls[nickname]

try:
redirects = 0
while True:

# Parse Url
parts = urlparse.urlparse(url)

# Parse host and port
endpoint = parts[1].split(':')
if len(endpoint) > 1:
service_host = endpoint[0]
service_port = int(endpoint[1])
# Set httplib class
if parts.scheme == 'http':
connection = httplib.HTTPConnection(parts.netloc)
elif parts.scheme == 'https':
connection = httplib.HTTPSConnection(parts.netloc)
else:
service_host = endpoint[0]
service_port = 80
raise Exception("Invalid scheme: %s" % parts.scheme)

# Setup Connection
connection = httplib.HTTPConnection(service_host,
service_port)

url = "%s?%s" % (parts[2], parts[4])

url = "%s?%s" % (parts.path, parts.query)
connection.request("GET", url)
response = connection.getresponse()
data = response.read()
Expand All @@ -93,10 +90,14 @@ def collect(self):
break
url = headers['location']
connection.close()

redirects += 1
if redirects > self.config['redirects']:
raise Exception("Too many redirects!")
except Exception, e:
self.log.error(
"Error retrieving HTTPD stats for host %s:%s, url '%s': %s",
service_host, str(service_port), url, e)
"Error retrieving HTTPD stats for '%s': %s",
url, e)
continue

exp = re.compile('^([A-Za-z ]+):\s+(.+)$')
Expand Down