Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
help it no werk
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaz492 committed Feb 6, 2017
1 parent 71c125d commit f5eaa2e
Showing 1 changed file with 28 additions and 50 deletions.
78 changes: 28 additions & 50 deletions system/cachetMonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
from system.logging import Logger


from utils import Utils

'''
Expand Down Expand Up @@ -43,6 +44,7 @@


class Cachet(object):

httpErrors = {
# Cloudflare Errors
520: "Web server is returning an unknown error (Cloudflare)",
Expand Down Expand Up @@ -136,105 +138,81 @@ def checkSites(self):
r = requests.get(url, verify=True)
# self.utils.postMetricsPointsByID(1, r.elapsed.total_seconds() * 1000)
if r.status_code not in status_codes and r.status_code not in self.httpErrors:
error_code = '%s check **failed** - %s \n\n`%s %s HTTP StatusError: %s`' % (
url, localtime, request_method, url, httplib.responses[r.status_code])
error_code = '%s check **failed** - %s \n\n`%s %s HTTP StatusError: %s`' % (url, localtime, request_method, url, httplib.responses[r.status_code])
if not incident_id:
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1,
component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn("%s" % error_code.strip('\n').strip('`'))
elif r.status_code not in status_codes and r.status_code in self.httpErrors:
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (
url, localtime, request_method, url, self.httpErrors[r.status_code])
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (url, localtime, request_method, url, self.httpErrors[r.status_code])
if not incident_id:
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1,
component_id=c_id, component_status=4)
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn("%s" % error_code.replace('\n', '').replace('`', ''))
elif request_method.lower() == "post":
r = requests.get(url, verify=True)
if r.status_code not in status_codes and r.status_code not in self.httpErrors:
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (
url, localtime, request_method, url, httplib.responses[r.status_code])
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (url, localtime, request_method, url, httplib.responses[r.status_code])
if not incident_id:
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1,
component_id=c_id, component_status=4)
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn("%s" % error_code.strip('\n').strip('`'))
elif r.status_code not in status_codes and r.status_code in self.httpErrors:
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (
url, localtime, request_method, url, self.httpErrors[r.status_code])
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Status Error: %s`' % (url, localtime, request_method, url, self.httpErrors[r.status_code])
if not incident_id:
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1,
component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: HTTP Status Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn("%s" % error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.HTTPError as e:
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Error: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s HTTP Error: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: HTTP Error' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: HTTP Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.SSLError as e:
error_code = '%s check **failed** - %s \n\n`%s %s SSL Error: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s SSL Error: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: SSL Error' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: SSL Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.ConnectionError as e:
error_code = '%s check **failed** - %s \n\n`%s %s Connection Error: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s Connection Error: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: Connection Error' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: Connection Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.Timeout as e:
error_code = '%s check **failed** - %s \n\n`%s %s Request Timeout: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s Request Timeout: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: Request Timeout' % url, error_code, 1, 1, component_id=c_id,
component_status=2)
self.utils.postIncidents('%s: Request Timeout' % url, error_code, 1, 1, component_id=c_id, component_status=2)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.TooManyRedirects as e:
error_code = '%s check **failed** - %s \n\n`%s %s Too Many Redirects: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s Too Many Redirects: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: Too Many Redirects' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: Too Many Redirects' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except requests.exceptions.RetryError as e:
error_code = '%s check **failed** - %s \n\n`%s %s Retry Error: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s Retry Error: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: Retry Error' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: Retry Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.warn(error_code.replace('\n', '').replace('`', ''))
except Exception as e:
error_code = '%s check **failed** - %s \n\n`%s %s Unexpected Error: %s`' % (
url, localtime, request_method, url, e)
error_code = '%s check **failed** - %s \n\n`%s %s Unexpected Error: %s`' % (url, localtime, request_method, url, e)
if not incident_id:
self.utils.postIncidents('%s: Unexpected Error' % url, error_code, 1, 1, component_id=c_id,
component_status=4)
self.utils.postIncidents('%s: Unexpected Error' % url, error_code, 1, 1, component_id=c_id, component_status=4)
if current_status is not 4:
self.utils.putComponentsByID(c_id, status=4)
self.logs.error(error_code.replace('\n', '').replace('`', ''))
Expand All @@ -244,10 +222,8 @@ def checkSites(self):
self.utils.putComponentsByID(c_id, status=1)
self.logs.info("Issue with %s has been resolved" % url)
elif current_status is not 1 and incident_id:
incident_description = "Resolved at %s\n\n***\n\n%s" % (
localtime, self.getIncidentInfo(incident_id))
self.utils.putIncidentsByID(incident_id, message=incident_description, status=4,
component_id=c_id, component_status=1)
incident_description = "Resolved at %s\n\n***\n\n%s" % (localtime, self.getIncidentInfo(incident_id))
self.utils.putIncidentsByID(incident_id, message=incident_description, status=4, component_id=c_id, component_status=1)
else:
self.logs.info("%s no issues found" % url)

Expand All @@ -273,3 +249,5 @@ def getIncidentInfo(self, i_id):
incident = self.utils.getIncidentsByID(i_id).json()
i_description = incident['data']['message']
return i_description


0 comments on commit f5eaa2e

Please sign in to comment.