From 1964ab24f78f30f230e982dcdb956bd72682b225 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Tue, 2 Jul 2019 21:59:01 -0400 Subject: [PATCH] Add health check endpoint --- netbox/netbox/configuration.example.py | 3 +++ netbox/netbox/settings.py | 4 ++++ netbox/netbox/urls.py | 5 +++++ requirements.txt | 1 + 4 files changed, 13 insertions(+) diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index ebc3d4540..2e152fa69 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -166,6 +166,9 @@ TIME_ZONE = 'UTC' # database be configured and accessible by NetBox. WEBHOOKS_ENABLED = False +# The health check endpoint reports if NetBox is operational, Set this to True to enable it. +HEALTH_CHECK_ENABLED = False + # Date/time formatting. See the following link for supported formats: # https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date DATE_FORMAT = 'N j, Y' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 3ee05a24f..123f14487 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -92,6 +92,7 @@ SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s') TIME_FORMAT = getattr(configuration, 'TIME_FORMAT', 'g:i a') TIME_ZONE = getattr(configuration, 'TIME_ZONE', 'UTC') WEBHOOKS_ENABLED = getattr(configuration, 'WEBHOOKS_ENABLED', False) +HEALTH_CHECK_ENABLED = getattr(configuration, 'HEALTH_CHECK_ENABLED', False) # @@ -189,6 +190,9 @@ INSTALLED_APPS = [ if WEBHOOKS_ENABLED: INSTALLED_APPS.append('django_rq') +if HEALTH_CHECK_ENABLED: + INSTALLED_APPS.append('watchman') + # Middleware MIDDLEWARE = ( 'debug_toolbar.middleware.DebugToolbarMiddleware', diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index ef2c9ec28..853c5cee4 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -79,6 +79,11 @@ if settings.METRICS_ENABLED: path('', include('django_prometheus.urls')), ] +if settings.HEALTH_CHECK_ENABLED: + _patterns += [ + path(r'health/', include('watchman.urls')), + ] + # Prepend BASE_PATH urlpatterns = [ path(r'{}'.format(settings.BASE_PATH), include(_patterns)) diff --git a/requirements.txt b/requirements.txt index 3ad165a4b..a6cdf7845 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,7 @@ django-tables2==2.0.6 django-taggit==1.1.0 django-taggit-serializer==0.1.7 django-timezone-field==3.0 +django-watchman==0.17.0 djangorestframework==3.9.4 drf-yasg[validation]==1.16.0 graphviz==0.10.1