Python plugin for cachet that monitors an URL, verifying it's response status and latency. The frequency the URL is tested is configurable, along with the assertion applied to the request response.
This project is available at PyPI: https://pypi.python.org/pypi/cachet-url-monitor
yaml
endpoints:
- name: Google
url: http://www.google.com
method: GET
header:
SOME-HEADER: SOME-VALUE
timeout: 1 # seconds
expectation:
- type: HTTP_STATUS
status_range: 200-205
- type: LATENCY
threshold: 1
- type: REGEX
regex: ".*<body>.*"
allowed_fails: 0
component_id: 1
metric_id: 1
action:
- UPDATE_STATUS
public_incidents: true
latency_unit: ms
frequency: 5
- name: Amazon
url: http://www.amazon.com
method: GET
header:
SOME-HEADER: SOME-VALUE
timeout: 1 # seconds
expectation:
- type: HTTP_STATUS
status_range: 200-205
incident: MAJOR
- type: LATENCY
threshold: 1
- type: REGEX
regex: ".*<body>.*"
threshold: 10
allowed_fails: 0
component_id: 2
action:
- CREATE_INCIDENT
public_incidents: true
latency_unit: ms
frequency: 5
- name: Insecure-site
url: https://www.Insecure-site-internal.com
method: GET
header:
SOME-HEADER: SOME-VALUE
insecure: true
timeout: 1 # seconds
expectation:
- type: HTTP_STATUS
status_range: 200-205
allowed_fails: 0
component_id: 2
action:
- CREATE_INCIDENT
public_incidents: true
frequency: 5
cachet:
api_url: http://status.cachethq.io/api/v1
token:
- type: ENVIRONMENT_VARIABLE
value: CACHET_TOKEN
- type: AWS_SECRETS_MANAGER
secret_name: cachethq
secret_key: token
region: us-west-2
- type: TOKEN
value: my_token
webhooks:
- url: "https://push.example.com/message?token=<apptoken>"
params:
title: "{title}"
message: "{message}"
priority: 5
messages:
incident_outage: "{name} is unavailable"
incident_operational: "{name} is operational"
incident_performance: "{name} has degraded performance"
200
will be converted to 200-201
.CREATE_INCIDENT
or UPDATE_STATUS
are set.ms
, s
, m
, h
.Each expectation
has their own default incident status. It can be overridden by setting the incident
property to
any of the following values:
- PARTIAL
- MAJOR
- PERFORMANCE
By choosing any of the aforementioned statuses, it will let you control the kind of incident it should be considered
. These are the default incident status for each expectation
type:
| Expectation | Incident status | | ----------- | --------------- | | HTTP_STATUS | PARTIAL | | LATENCY | PERFORMANCE | | REGEX | PARTIAL |
Following parameters are available in webhook interpolation
| Parameter | Description |
| --------- | ----------- |
| {title}
| Event title, includes endpoint name and short status |
| {message}
| Event message, same as sent to Cachet |
This tools can integrate with AWS Secrets Manager, where the token is fetched directly from the service. In order to
get this functionality working, you will need to setup the AWS credentials into the container. The easiest way would
be setting the environment variables:
bash
$ docker run --rm -it -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa -v "$PWD"/my_config.yml:/usr/src/app/config/config.yml:ro mtakaki/cachet-url-monitor
The application should be installed using virtualenv, through the following command:
bash
$ git clone https://github.com/mtakaki/cachet-url-monitor.git
$ cd cachet-url-monitor
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python3 setup.py install
To start the agent:
bash
$ python3 cachet_url_monitor/scheduler.py config.yml
You can run the agent in docker, so you won't need to worry about installing python, virtualenv, or any other
dependency into your OS. The Dockerfile
is already checked in and it's ready to be used.
You have two choices, checking this repo out and building the docker image or it can be pulled directly from
dockerhub. You will need to create your own custom config
.yml
file and run (it will pull latest):
bash
$ docker pull mtakaki/cachet-url-monitor
$ docker run --rm -it -v "$PWD":/usr/src/app/config/ mtakaki/cachet-url-monitor
If you're going to use a file with a name other than config.yml
, you will need to map the local file, like this:
bash
$ docker run --rm -it -v "$PWD"/my_config.yml:/usr/src/app/config/config.yml:ro mtakaki/cachet-url-monitor
Docker compose has been removed from this repo as it had a dependency on PostgreSQL and it slightly complicated how it works. This has been kindly handled on: https://github.com/boonisz/cachet-url-monitor-dc It facilitates spawning CachetHQ with its dependencies and cachet-url-monitor alongside to it.
In order to expedite the creation of your configuration file, you can use the client to automatically scrape the
CachetHQ instance and spit out a YAML file. It can be used like this:
bash
$ python cachet_url_monitor/client.py http://localhost/api/v1 my-token test.yml
Or from docker (you will end up with a test.yml
in your $PWD/tmp
folder):
bash
$ docker run --rm -it -v $PWD/tmp:/home/tmp/ mtakaki/cachet-url-monitor python3.7 ./cachet_url_monitor/client.py http://localhost/api/v1 my-token /home/tmp/test.yml
The arguments are:
- URL, the CachetHQ API URL, so that means appending /api/v1
to your hostname.
- token, the token that has access to your CachetHQ instance.
- filename, the file where it should write the configuration.
Because we can't predict what expectations will be needed, it will default to these behavior:
- Verify a [200-300[ HTTP status range.
- If status fail, make the incident major and public.
- Frequency of 30 seconds.
- GET
request.
- Timeout of 1s.
- We'll read the link
field from the components and use it as the URL.
If it's throwing the following exception:
python
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='redacted', port=443): Max retries exceeded with url: /api/v1/components/19 (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))
It can be resolved by setting the CA bundle environment variable REQUESTS_CA_BUNDLE
pointing at your certificate
file. It can either be set in your python environment, before running this tool, or in your docker container.
If you want to contribute to this project, feel free to fork this repo and post PRs with any improvements or bug fixes. This is highly appreciated, as it's been hard to deal with numerous requests coming my end.
This repo is setup with pre-commit hooks and it should ensure code style is consistent
. The steps to start development on this repo is the same as the setup aforementioned above:
bash
$ git clone https://github.com/mtakaki/cachet-url-monitor.git
$ cd cachet-url-monitor
$ pre-commit install
$ virtualenv venv
$ source venv/bin/activate
$ tox
Bumps ipython from 7.16.3 to 8.10.0.
Sourced from ipython's releases.
See https://pypi.org/project/ipython/
We do not use GitHub release anymore. Please see PyPI https://pypi.org/project/ipython/
15ea1ed
release 8.10.0560ad10
DOC: Update what's new for 8.10 (#13939)7557ade
DOC: Update what's new for 8.10385d693
Merge pull request from GHSA-29gw-9793-fvw7e548ee2
Swallow potential exceptions from showtraceback() (#13934)0694b08
MAINT: mock slowest test. (#13885)8655912
MAINT: mock slowest test.a011765
Isolate the attack tests with setUp and tearDown methodsc7a9470
Add some regression tests for this changefd34cf5
Swallow potential exceptions from showtraceback()Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
if header is not present in a endpoint configuration, the insecure flag is not taken into account
Hi, I am looking out for a solution where our Cachet Status Page can sort the components based on the status (For ex: Outage URL should be listed first in the status page UI). I followed the documentation, but not clear where exactly to make changes. Can anyone help please.
Ref: https://docs.cachethq.io/docs/advanced-api-usage
What I think, I should make changes in the config.yml file -> api_url section, but that's giving me an error:
Config_File:
Error:
Traceback (most recent call last):
File "cachet_url_monitor/scheduler.py", line 160, in
Hi There,
is there any example for supervising databases, such as mariadb
or postgresql
?
I think this would be useful for documentation (quick-start).
Further, some recommendations for supervising systems would be nice, e.g.:
* HTTP 200-300 check for general availability incident: MAJOR
* HTTP 200-300 using latency for incident: PERFORMANCE
* etc.
Is something like that available?
As part of #99, cachet-url-monitor now supports different token providers. It included refactoring, so it can be easily extended to support new sources.
Still backwards compatible with old configuration files.
Thank you @nijel for the great new additions!
Configuration
.Thanks to @nijel, we got numerous bug fixes: - Removing usage of scheduler and relying on thread sleep. - Incorrect location of latency unit. - Fixing the metrics push that was pushing it twice.
Accidentally introduced a bug when moving code from configuration.py
to scheduler.py
(#81). Kindly fixed by @chris-str-cst through #82.
Fixing bug introduced in 0.6.2 when a CachetClient
class was created and it was preventing it from updating component status. It wasn't calling ComponentStatus.value
.
Upgrading dependencies: - PyYAML 5.3
Dev requirements: - coverage 5.0.3 - coveralls 1.10.0 - mock 3.0.5 - pytest 5.3.3
And finally fixing the code coverage metrics, that was broken due to running pytest with the installed package, rather than the source code.
cachethq monitoring cachet-url-monitor docker