Skip to content

Commit

Permalink
Merge pull request #13 from rahulg963/patch-2
Browse files Browse the repository at this point in the history
Correction in Import statement of configuration.py
  • Loading branch information
mtakaki committed Jun 25, 2016
2 parents b018f9e + 969a2b1 commit 23326fd
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions cachet_url_monitor/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import time

import cachet_url_monitor.status
import status as st
import os
import re
import requests
Expand Down Expand Up @@ -126,21 +126,21 @@ def evaluate(self):
except requests.ConnectionError:
self.message = 'The URL is unreachable: %s %s' % (self.endpoint_method, self.endpoint_url)
self.logger.warning(self.message)
self.status = cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE
self.status = st.COMPONENT_STATUS_PARTIAL_OUTAGE
return
except requests.HTTPError:
self.message = 'Unexpected HTTP response'
self.logger.exception(self.message)
self.status = cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE
self.status = st.COMPONENT_STATUS_PARTIAL_OUTAGE
return
except requests.Timeout:
self.message = 'Request timed out'
self.logger.warning(self.message)
self.status = cachet_url_monitor.status.COMPONENT_STATUS_PERFORMANCE_ISSUES
self.status = st.COMPONENT_STATUS_PERFORMANCE_ISSUES
return

# We initially assume the API is healthy.
self.status = cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL
self.status = st.COMPONENT_STATUS_OPERATIONAL
self.message = ''
for expectation in self.expectations:
status = expectation.get_status(self.request)
Expand Down Expand Up @@ -187,7 +187,7 @@ def push_incident(self):
"""If the component status has changed, we create a new incident (if this is the first time it becomes unstable)
or updates the existing incident once it becomes healthy again.
"""
if hasattr(self, 'incident_id') and self.status == cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL:
if hasattr(self, 'incident_id') and self.status == st.COMPONENT_STATUS_OPERATIONAL:
# If the incident already exists, it means it was unhealthy but now it's healthy again.
params = {'status': 4, 'visible': 1, 'component_id': self.component_id, 'component_status': self.status,
'notify': True}
Expand All @@ -203,7 +203,7 @@ def push_incident(self):
else:
self.logger.warning('Incident update failed with status [%d], message: "%s"' % (
incident_request.status_code, self.message))
elif not hasattr(self, 'incident_id') and self.status != cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL:
elif not hasattr(self, 'incident_id') and self.status != st.COMPONENT_STATUS_OPERATIONAL:
# This is the first time the incident is being created.
params = {'name': 'URL unavailable', 'message': self.message, 'status': 1, 'visible': 1,
'component_id': self.component_id, 'component_status': self.status, 'notify': True}
Expand Down Expand Up @@ -254,9 +254,9 @@ def __init__(self, configuration):

def get_status(self, response):
if response.status_code == self.status:
return cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL
return st.COMPONENT_STATUS_OPERATIONAL
else:
return cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE
return st.COMPONENT_STATUS_PARTIAL_OUTAGE

def get_message(self, response):
return 'Unexpected HTTP status (%s)' % (response.status_code,)
Expand All @@ -271,9 +271,9 @@ def __init__(self, configuration):

def get_status(self, response):
if response.elapsed.total_seconds() <= self.threshold:
return cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL
return st.COMPONENT_STATUS_OPERATIONAL
else:
return cachet_url_monitor.status.COMPONENT_STATUS_PERFORMANCE_ISSUES
return st.COMPONENT_STATUS_PERFORMANCE_ISSUES

def get_message(self, response):
return 'Latency above threshold: %.4f seconds' % (response.elapsed.total_seconds(),)
Expand All @@ -289,9 +289,9 @@ def __init__(self, configuration):

def get_status(self, response):
if self.regex.match(response.text):
return cachet_url_monitor.status.COMPONENT_STATUS_OPERATIONAL
return st.COMPONENT_STATUS_OPERATIONAL
else:
return cachet_url_monitor.status.COMPONENT_STATUS_PARTIAL_OUTAGE
return st.COMPONENT_STATUS_PARTIAL_OUTAGE

def get_message(self, response):
return 'Regex did not match anything in the body'
Expand Down

0 comments on commit 23326fd

Please sign in to comment.