Package: django-alive
django-alive 🕺Provides two healthcheck endpoints for your Django application:AliveVerifies the WSGI server is responding.Default URL:/-/alive/Success:status code:200content:okFailure: This view never returns a failure. A failure would mean your WSGI server is not running.HealthVerifies services are ready.Default URL:/-/health/Success:status_code:200content:{"healthy": true}Failure:status_code:503content:{"healthy": false, "errors": ["error 1", "error 2"]}By default the health endpoint will test the database connection, but can be configured to check the cache, staticfiles, or any additional custom checks.Supports Django 1.10+ on both Python 2 & 3.Installpip install django-aliveConfigureAdd this to your project'surlpatterns:path("-/",include("django_alive.urls"))For versions before Django 2.0, use:url(r"-/",include("django_alive.urls"))If you wish to use thehealthcheckmanagement command, adddjango_aliveto theINSTALLED_APPS.Enabling ChecksThe default "health" endpoint will test a simpleSELECT 1query on the database. Additional checks can be enabled in your Django settings.Use theALIVE_CHECKSsetting to configure the checks to include. It is a dictionary with the path to a Python function as a key and any keyword arguments to pass to that function as a value. A full example:ALIVE_CHECKS={"django_alive.checks.check_database":{},"django_alive.checks.check_staticfile":{"filename":"img/favicon.ico",},"django_alive.checks.check_cache":{"cache":"session","key":"test123",},"django_alive.checks.check_migrations":{},}Built-in ChecksDefined indjango_alive.checks.defcheck_cache(key="django-alive",cache="default")Fetch a cache key against the specified cache.Parameters:key(str):  Cache key to fetch (does not need to exist)cache(str):  Cache alias to execute againstdefcheck_database(query="SELECT 1",database="default")Run a SQL query against the specified database.Parameters:query(str):  SQL to executedatabase(str):  Database alias to execute againstdefcheck_migrations(alias=None)Verify all defined migrations have been appliedParameters:alias(str):  An optional database alias (default: check all defined databases)defcheck_staticfile(filename)Verify a static file is reachableParameters:filename(str):  static file to verifyManagement CommandIn addition to the view, the configured healthchecks can also be run via a management command withmanage.py healthcheck. This will exit with an error code if all the healthchecks do not pass.Custom Checksdjango-aliveis designed to easily extend with your own custom checks. Simply define a function which performs your check and raises adjango_alive.HealthcheckFailureexception in the event of a failure. Seechecks.pyfor some examples on how to write a check.DisablingALLOWED_HOSTSfor HealthchecksOften, load balancers will not pass aHostheader when probing a healthcheck endpoint. This presents a problem forDjango's host header validation. A middleware is included that will turn off the host checking only for the healthcheck endpoints. This is safe since these views never do anything with theHostheader.Enable the middleware by inserting thisat the beginningof yourMIDDLEWARE:MIDDLEWARE=["django_alive.middleware.healthcheck_bypass_host_check",# ...]HandlingSECURE_SSL_REDIRECTIf your load balancer is doing HTTPS termination and you haveSECURE_SSL_REDIRECT=Truein your settings, you want to make sure that your healtcheck URLs are not also redirected to HTTPS. In that case, add the following to your settings:SECURE_REDIRECT_EXEMPT=[r"^-/"]# django-alive URLs1.2.1 (2021-07-23)Update PyPI metadata1.2.0 (2021-07-23)Updated test matrix. Python 2 no longer "officially" supported.Prevent Traceback in middleware if URLs are not setup1.1.0 (2019-11-06)Addedhealthcheckmanagement commandAdded optionalcheck_migrationshealthcheck1.0.1 (2018-09-10)Documentation improvementsPython 3.7 support1.0.0 (2018-08-21)Initial release