diff --git a/src/collectors/httpd/httpd.py b/src/collectors/httpd/httpd.py index 4ceeab48c..ee1e5a0e1 100644 --- a/src/collectors/httpd/httpd.py +++ b/src/collectors/httpd/httpd.py @@ -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 @@ -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 @@ -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() @@ -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+(.+)$')