Package: http-rx
HTTP Rx - Your HTTP DoctorHTTP Rxis 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.InstallingThis package is available on the Python Package Index (PyPi) and can be installed with pip:pip install --upgrade http-rxAlternatively, you may clone this repository and install from the source code:python setup.py installConfigurationHTTP Rx is very dynamic and configurable, inspired by the Java Spring framework, the health checker looks for aconfig.jsonfile in your current directory, or if you specify theRX_CONFIGenvironment 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"}}]}]}Therequestskey 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 responseFor 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.StatusCodeCheckclassThetypeconfiguration 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.ExtendingHTTP 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 thehttp-rxpackage:python3 -m virtualenv venv
source venv/bin/activate
pip install http-rxThen simply create your own custom health check that extends HTTP Rx'sCheckbase class:"""content.py"""importrxfromrximportcheckclassCheckContentType(check.Check):def__init__(self,conf):super().__init__(conf)self.expected_content_type=conf.get('expected','text/html')defresult(self,resp):content_type=resp.headers.get('content-type',None)healthy=content_type==self.expected_content_typereturncheck.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.