mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
Add client header option to requests (#61)
* Add header option * Add header option * Add unit test for headers * Add client header * Remove environ for HEADER environ does not support dictionaries, so HEADER can't be passed.
This commit is contained in:
@@ -97,6 +97,7 @@ class Configuration(object):
|
||||
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.endpoint_header = self.data['endpoint'].get('header') or None
|
||||
self.allowed_fails = os.environ.get('ALLOWED_FAILS') or self.data['endpoint'].get('allowed_fails') or 0
|
||||
|
||||
self.api_url = os.environ.get('CACHET_API_URL') or self.data['cachet']['api_url']
|
||||
@@ -172,7 +173,10 @@ class Configuration(object):
|
||||
according to the expectation results.
|
||||
"""
|
||||
try:
|
||||
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout)
|
||||
if self.endpoint_header is not None:
|
||||
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout, headers=self.endpoint_header)
|
||||
else:
|
||||
self.request = requests.request(self.endpoint_method, self.endpoint_url, timeout=self.endpoint_timeout)
|
||||
self.current_timestamp = int(time.time())
|
||||
except requests.ConnectionError:
|
||||
self.message = 'The URL is unreachable: %s %s' % (self.endpoint_method, self.endpoint_url)
|
||||
|
||||
Reference in New Issue
Block a user