Extensible HTTP health checker for Python
Project description
HTTP Rx - Your HTTP Doctor
HTTP Rx is a simple site/http monitor for your websites and HTTP endpoints. The tool monitors a given list of endpoint configurations and logs errors if the expected health check does not pass.
Installing
This package is available on the Python Package Index (PyPi) and can be installed with pip:
pip install --upgrade http-rx
Alternatively, you may clone this repository and install from the source code:
python setup.py install
Configuration
HTTP Rx is very dynamic and configurable, inspired by the Java Spring framework, the health checker looks for a config.json file in your current directory, or if you specify the RX_CONFIG environment variable you can change the path to your config file.
This JSON config file is structured like so:
{
"logLevel": "INFO",
"report": {
"interval": 5.0
},
"requests": [
{
"name": "GitHub Profile",
"url": "https://github.com/zcking",
"method": "GET",
"intervalSeconds": 2.0,
"checks": [
{
"type": "rx.check.StatusCodeCheck",
"expected": 201
},
{
"type": "rx.check.HeaderCheck",
"headers": {
"Content-Type": "text/html"
}
}
]
}
]
}
The requests key is a list of http targets to check,
each of which has the following settings:
url- the HTTP(s) target to requestmethod- the HTTP verb to request with; defaults to"GET"name- human-friendly label for the request; defaults to{method}:{url}data- request body to send; defaults toNoneheaders- request headers to send; defaults to[]checks- list of health check configurations to perform on the HTTP response
For the check configurations, you must specify the following configuration(s):
type- fully qualified Python class; must be a derivative of therx.check.Checkbase class. Defaults to therx.check.StatusCodeCheckclass
The type configuration is how you may specify your own custom health check classes when extending http-rx. See the next section on doing just this.
Note: the entire check configuration object is passed to the check class's __init__ method for arbitrary custom configuration. See the built-in health checks in this repository for examples.
Extending
HTTP Rx is setup in a framework manner, allowing you to easily extend it with your own custom health checks, written in Python.
For example:
Create a fresh virtual environment to install the http-rx package:
python3 -m virtualenv venv
source venv/bin/activate
pip install http-rx
Then simply create your own custom health check that extends HTTP Rx's Check base class:
"""
content.py
"""
import rx
from rx import check
class CheckContentType(check.Check):
def __init__(self, conf):
super().__init__(conf)
self.expected_content_type = conf.get('expected', 'text/html')
def result(self, resp):
content_type = resp.headers.get('content-type', None)
healthy = content_type == self.expected_content_type
return check.Result(
resp=resp,
is_healthy=healthy,
fail_reason=f'expected content type of {self.expected_content_type} but received {content_type}'
)
if __name__ == '__main__':
rx.run()
And your config file to go along with it:
{
"report": {
"interval": 2.0
},
"requests": [
{
"name": "GitHub Profile",
"url": "https://github.com/zcking",
"method": "GET",
"intervalSeconds": 0,
"checks": [
{
"type": "__main__.CheckContentType",
"expected": "application/json"
}
]
}
]
}
Notice in this simple example that the module name is __main__ because we're executing it as a script. If you were to write your own Python package with submodules etc. this may not be the case.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http_rx-0.5.0.tar.gz.
File metadata
- Download URL: http_rx-0.5.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
393ae49e2b625e7796a2a3b56fdb777c43e635382a2081b6018b99a198869386
|
|
| MD5 |
c195f3c7ccbf2a3f8af515429abe7a55
|
|
| BLAKE2b-256 |
bf16ee29826ae45620f73217c5d973f5ddc540b33b51e9aa38256519cd95990e
|
File details
Details for the file http_rx-0.5.0-py3-none-any.whl.
File metadata
- Download URL: http_rx-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c82d50002f9959309582d0c764d41ee4ef0b7a4c210c1dea5614591663e932af
|
|
| MD5 |
5bd877d15d1ea20f5e1619e12aaeebc8
|
|
| BLAKE2b-256 |
f95229082d3de78643b04181f60919491f6cdc7377f4f6d901e779a47258d037
|