mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-07 21:21:58 +00:00
Merge pull request #44 from mtakaki/mtakaki_manual_testing
Running some manual tests and updating Dockerfile
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
FROM python:2-onbuild
|
||||
FROM python:2.7-alpine
|
||||
MAINTAINER Mitsuo Takaki <mitsuotakaki@gmail.com>
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY requirements.txt /usr/src/app/
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY cachet_url_monitor/* /usr/src/app/cachet_url_monitor/
|
||||
|
||||
COPY config.yml /usr/src/app/config/
|
||||
VOLUME /usr/src/app/config/
|
||||
|
||||
|
||||
@@ -41,6 +41,16 @@ class ComponentNonexistentError(Exception):
|
||||
return repr('Component with id [%d] does not exist.' % (self.component_id,))
|
||||
|
||||
|
||||
class MetricNonexistentError(Exception):
|
||||
"""Exception raised when the component does not exist."""
|
||||
|
||||
def __init__(self, metric_id):
|
||||
self.metric_id = metric_id
|
||||
|
||||
def __str__(self):
|
||||
return repr('Metric with id [%d] does not exist.' % (self.metric_id,))
|
||||
|
||||
|
||||
def get_current_status(endpoint_url, component_id, headers):
|
||||
"""Retrieves the current status of the component that is being monitored. It will fail if the component does
|
||||
not exist or doesn't respond with the expected data.
|
||||
@@ -89,7 +99,10 @@ class Configuration(object):
|
||||
self.api_url = os.environ.get('CACHET_API_URL') or self.data['cachet']['api_url']
|
||||
self.component_id = os.environ.get('CACHET_COMPONENT_ID') or self.data['cachet']['component_id']
|
||||
self.metric_id = os.environ.get('CACHET_METRIC_ID') or self.data['cachet'].get('metric_id')
|
||||
self.default_metric_value = self.get_default_metric_value()
|
||||
|
||||
if self.metric_id is not None:
|
||||
self.default_metric_value = self.get_default_metric_value(self.metric_id)
|
||||
|
||||
# The latency_unit configuration is not mandatory and we fallback to seconds, by default.
|
||||
self.latency_unit = os.environ.get('LATENCY_UNIT') or self.data['cachet'].get('latency_unit') or 's'
|
||||
|
||||
@@ -105,10 +118,14 @@ class Configuration(object):
|
||||
for expectation in self.expectations:
|
||||
self.logger.info('Registered expectation: %s' % (expectation,))
|
||||
|
||||
def get_default_metric_value(self):
|
||||
def get_default_metric_value(self, metric_id):
|
||||
"""Returns default value for configured metric."""
|
||||
get_metric_request = requests.get('%s/metrics/%s' % (self.api_url, self.metric_id), headers=self.headers)
|
||||
return get_metric_request.json()['data']['default_value']
|
||||
get_metric_request = requests.get('%s/metrics/%s' % (self.api_url, metric_id), headers=self.headers)
|
||||
|
||||
if get_metric_request.ok:
|
||||
return get_metric_request.json()['data']['default_value']
|
||||
else:
|
||||
raise MetricNonexistentError(metric_id)
|
||||
|
||||
def get_action(self):
|
||||
"""Retrieves the action list from the configuration. If it's empty, returns an empty list.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
PyYAML==3.11
|
||||
PyYAML==3.12
|
||||
codacy-coverage==1.2.18
|
||||
ipython==4.2.0
|
||||
mock==2.0.0
|
||||
pudb==2016.1
|
||||
pytest==3.4.2
|
||||
pytest-cov==2.5.1
|
||||
requests==2.9.1
|
||||
schedule==0.3.2
|
||||
requests==2.18.4
|
||||
schedule==0.5.0
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
version: '2'
|
||||
services:
|
||||
monitor:
|
||||
build: .
|
||||
volumes:
|
||||
- .:/usr/src/app/
|
||||
@@ -1,3 +1,3 @@
|
||||
PyYAML==3.11
|
||||
requests==2.9.1
|
||||
schedule==0.3.2
|
||||
PyYAML==3.12
|
||||
requests==2.18.4
|
||||
schedule==0.5.0
|
||||
|
||||
Reference in New Issue
Block a user