Skip to content

Commit

Permalink
Merge pull request #35 from jacekszubert/better_url_handling
Browse files Browse the repository at this point in the history
Better url scheme handling
  • Loading branch information
mtakaki committed Mar 12, 2017
2 parents ffa141d + 22d0323 commit 284ef97
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cachet_url_monitor/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def get_current_status(endpoint_url, component_id, headers):
raise ComponentNonexistentError(component_id)


def normalize_url(url):
"""If passed url doesn't include schema return it with default one - http."""
if not url.lower().startswith('http'):
return 'http://%s' % url
return url


class Configuration(object):
"""Represents a configuration file, but it also includes the functionality
of assessing the API and pushing the results to cachet.
Expand All @@ -75,6 +82,7 @@ def __init__(self, config_file):

self.endpoint_method = os.environ.get('ENDPOINT_METHOD') or self.data['endpoint']['method']
self.endpoint_url = os.environ.get('ENDPOINT_URL') or self.data['endpoint']['url']
self.endpoint_url = normalize_url(self.endpoint_url)
self.endpoint_timeout = os.environ.get('ENDPOINT_TIMEOUT') or self.data['endpoint'].get('timeout') or 1

self.api_url = os.environ.get('CACHET_API_URL') or self.data['cachet']['api_url']
Expand Down Expand Up @@ -150,10 +158,6 @@ def evaluate(self):
self.logger.warning(self.message)
self.status = st.COMPONENT_STATUS_PERFORMANCE_ISSUES
return
except requests.exceptions.MissingSchema:
self.logger.info('No schema specified - using default http://')
self.endpoint_url = 'http://%s' % self.endpoint_url
self.evaluate()

# We initially assume the API is healthy.
self.status = st.COMPONENT_STATUS_OPERATIONAL
Expand Down

0 comments on commit 284ef97

Please sign in to comment.