From 45917f80144a1b583c000cc41135a8a836efe671 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 6 Dec 2019 11:52:28 -0500 Subject: [PATCH] Closes #3408: Remove WEBHOOKS_ENABLE configuration setting --- base_requirements.txt | 4 +++ docs/configuration/optional-settings.md | 8 ----- docs/installation/3-http-daemon.md | 9 ++---- docs/installation/migrating-to-systemd.md | 11 ++----- docs/installation/upgrading.md | 9 ++---- docs/release-notes/version-2.7.md | 7 ++++ netbox/extras/__init__.py | 14 -------- netbox/extras/apps.py | 39 ++++++++++------------- netbox/extras/webhooks.py | 2 +- netbox/netbox/admin.py | 9 +----- netbox/netbox/configuration.example.py | 4 --- netbox/netbox/settings.py | 6 +--- netbox/netbox/urls.py | 6 +--- requirements.txt | 1 + 14 files changed, 39 insertions(+), 90 deletions(-) diff --git a/base_requirements.txt b/base_requirements.txt index ca3f4ba6f..448cbc6bc 100644 --- a/base_requirements.txt +++ b/base_requirements.txt @@ -78,3 +78,7 @@ py-gfm # Extensive cryptographic library (fork of pycrypto) # https://github.com/Legrandin/pycryptodome pycryptodome + +# In-memory key/value store used for caching and queuing +# https://github.com/andymccurdy/redis-py +redis diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index 89532d4b7..a59e6485f 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -301,14 +301,6 @@ The time zone NetBox will use when dealing with dates and times. It is recommend --- -## WEBHOOKS_ENABLED - -Default: False - -Enable this option to run the webhook backend. See the docs section on the webhook backend [here](../../additional-features/webhooks/) for more information on setup and use. - ---- - ## Date and Time Formatting You may define custom formatting for date and times. For detailed instructions on writing format strings, please see [the Django documentation](https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date). diff --git a/docs/installation/3-http-daemon.md b/docs/installation/3-http-daemon.md index a3a186aeb..1226c2a49 100644 --- a/docs/installation/3-http-daemon.md +++ b/docs/installation/3-http-daemon.md @@ -199,18 +199,13 @@ timeout=120 errorlog='/opt/netbox/netbox.log' ``` -Then, restart the systemd daemon service to detect the netbox service and start the netbox service: +Finally, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time: ```no-highlight # systemctl daemon-reload # systemctl start netbox.service -# systemctl enable netbox.service -``` - -If using webhooks, also start the Redis worker: - -```no-highlight # systemctl start netbox-rq.service +# systemctl enable netbox.service # systemctl enable netbox-rq.service ``` diff --git a/docs/installation/migrating-to-systemd.md b/docs/installation/migrating-to-systemd.md index 8f207c6ad..6199b5511 100644 --- a/docs/installation/migrating-to-systemd.md +++ b/docs/installation/migrating-to-systemd.md @@ -89,17 +89,12 @@ timeout=120 errorlog='/opt/netbox/netbox.log' ``` -Then, restart the systemd daemon service to detect the netbox service and start the netbox service: +Finally, start the `netbox` and `netbox-rq` services and enable them to initiate at boot time: ```no-highlight # systemctl daemon-reload # systemctl start netbox.service -# systemctl enable netbox.service -``` - -If using webhooks, also start the Redis worker: - -```no-highlight # systemctl start netbox-rq.service +# systemctl enable netbox.service # systemctl enable netbox-rq.service -``` \ No newline at end of file +``` diff --git a/docs/installation/upgrading.md b/docs/installation/upgrading.md index e2744e9c9..6a2c0188f 100644 --- a/docs/installation/upgrading.md +++ b/docs/installation/upgrading.md @@ -84,17 +84,12 @@ This script: # Restart the WSGI Service -Finally, restart the WSGI service to run the new code. If you followed this guide for the initial installation, this is done using `systemctl: +Finally, restart the WSGI services to run the new code. If you followed this guide for the initial installation, this is done using `systemctl: ```no-highlight # sudo systemctl restart netbox -``` - -If using webhooks, also restart the Redis worker: - -```no-highlight # sudo systemctl restart netbox-rqworker ``` !!! note - It's possible you are still using supervisord instead of the linux native systemd. If you are still using supervisord you can restart the services by either restarting supervisord or by using supervisorctl to restart netbox. \ No newline at end of file + It's possible you are still using supervisord instead of the linux native systemd. If you are still using supervisord you can restart the services by either restarting supervisord or by using supervisorctl to restart netbox. diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index 2fc6e1c5e..b3f102b9f 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -88,6 +88,13 @@ Note that `CACHE_DATABASE` has been removed and the connection settings have bee `caching`. This allows the user to make use of separate Redis instances and/or databases if desired. Full connection details are required in both sections, even if they are the same. +### WEBHOOKS_ENABLED Configuration Setting Removed ([#3408](https://github.com/netbox-community/netbox/issues/3408)) + +As `django-rq` is now a required library, NetBox assumes that the RQ worker process is running. The installation and +upgrade documentation has been updated to reflect this, and the `WEBHOOKS_ENABLED` configuration parameter is no longer +used. Please ensure that both the NetBox WSGI service and the RQ worker process are running on all production +installations. + ### API Choice Fields Now Use String Values ([#3569](https://github.com/netbox-community/netbox/issues/3569)) NetBox's REST API presents fields which reference a particular choice as a dictionary with two keys: `value` and diff --git a/netbox/extras/__init__.py b/netbox/extras/__init__.py index c7e9c66ad..3db5f9c25 100644 --- a/netbox/extras/__init__.py +++ b/netbox/extras/__init__.py @@ -1,15 +1 @@ -from django.conf import settings -from django.core.exceptions import ImproperlyConfigured - - default_app_config = 'extras.apps.ExtrasConfig' - -# check that django-rq is installed and we can connect to redis -if settings.WEBHOOKS_ENABLED: - try: - import django_rq - except ImportError: - raise ImproperlyConfigured( - "django-rq is not installed! You must install this package per " - "the documentation to use the webhook backend." - ) diff --git a/netbox/extras/apps.py b/netbox/extras/apps.py index 25c7cd5a2..f8c5a98e6 100644 --- a/netbox/extras/apps.py +++ b/netbox/extras/apps.py @@ -1,6 +1,7 @@ from django.apps import AppConfig from django.conf import settings from django.core.exceptions import ImproperlyConfigured +import redis class ExtrasConfig(AppConfig): @@ -10,26 +11,18 @@ class ExtrasConfig(AppConfig): import extras.signals - # Check that we can connect to the configured Redis database if webhooks are enabled. - if settings.WEBHOOKS_ENABLED: - try: - import redis - except ImportError: - raise ImproperlyConfigured( - "WEBHOOKS_ENABLED is True but the redis Python package is not installed. (Try 'pip install " - "redis'.)" - ) - try: - rs = redis.Redis( - host=settings.WEBHOOKS_REDIS_HOST, - port=settings.WEBHOOKS_REDIS_PORT, - db=settings.WEBHOOKS_REDIS_DATABASE, - password=settings.WEBHOOKS_REDIS_PASSWORD or None, - ssl=settings.WEBHOOKS_REDIS_SSL, - ) - rs.ping() - except redis.exceptions.ConnectionError: - raise ImproperlyConfigured( - "Unable to connect to the Redis database. Check that the Redis configuration has been defined in " - "configuration.py." - ) + # Check that we can connect to the configured Redis database. + try: + rs = redis.Redis( + host=settings.WEBHOOKS_REDIS_HOST, + port=settings.WEBHOOKS_REDIS_PORT, + db=settings.WEBHOOKS_REDIS_DATABASE, + password=settings.WEBHOOKS_REDIS_PASSWORD or None, + ssl=settings.WEBHOOKS_REDIS_SSL, + ) + rs.ping() + except redis.exceptions.ConnectionError: + raise ImproperlyConfigured( + "Unable to connect to the Redis database. Check that the Redis configuration has been defined in " + "configuration.py." + ) diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py index c95cb9f31..00c61cfb3 100644 --- a/netbox/extras/webhooks.py +++ b/netbox/extras/webhooks.py @@ -14,7 +14,7 @@ def enqueue_webhooks(instance, user, request_id, action): Find Webhook(s) assigned to this instance + action and enqueue them to be processed """ - if not settings.WEBHOOKS_ENABLED or instance._meta.label.lower() not in WEBHOOK_MODELS: + if instance._meta.label.lower() not in WEBHOOK_MODELS: return # Retrieve any applicable Webhooks diff --git a/netbox/netbox/admin.py b/netbox/netbox/admin.py index 27a033094..222c6ffc5 100644 --- a/netbox/netbox/admin.py +++ b/netbox/netbox/admin.py @@ -11,6 +11,7 @@ class NetBoxAdminSite(AdminSite): site_header = 'NetBox Administration' site_title = 'NetBox' site_url = '/{}'.format(settings.BASE_PATH) + index_template = 'django_rq/index.html' admin_site = NetBoxAdminSite(name='admin') @@ -18,11 +19,3 @@ admin_site = NetBoxAdminSite(name='admin') # Register external models admin_site.register(Group, GroupAdmin) admin_site.register(User, UserAdmin) - -# Modify the template to include an RQ link if django_rq is installed (see RQ_SHOW_ADMIN_LINK) -if settings.WEBHOOKS_ENABLED: - try: - import django_rq - admin_site.index_template = 'django_rq/index.html' - except ImportError: - pass diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index a209f5c12..bceb7ab17 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -178,10 +178,6 @@ SESSION_FILE_PATH = None # Time zone (default: UTC) TIME_ZONE = 'UTC' -# The webhooks backend is disabled by default. Set this to True to enable it. Note that this requires a Redis -# database be configured and accessible by NetBox. -WEBHOOKS_ENABLED = False - # Date/time formatting. See the following link for supported formats: # https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date DATE_FORMAT = 'N j, Y' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index cdd508029..49566eee7 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -92,7 +92,6 @@ SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H 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) # @@ -184,6 +183,7 @@ INSTALLED_APPS = [ 'corsheaders', 'debug_toolbar', 'django_filters', + 'django_rq', 'django_tables2', 'django_prometheus', 'mptt', @@ -203,10 +203,6 @@ INSTALLED_APPS = [ 'drf_yasg', ] -# Only load django-rq if the webhook backend is enabled -if WEBHOOKS_ENABLED: - INSTALLED_APPS.append('django_rq') - # Middleware MIDDLEWARE = ( 'debug_toolbar.middleware.DebugToolbarMiddleware', diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index f39040baf..6b6dfe22d 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -59,14 +59,10 @@ _patterns = [ # Admin path(r'admin/', admin_site.urls), + path(r'admin/webhook-backend-status/', include('django_rq.urls')), ] -if settings.WEBHOOKS_ENABLED: - _patterns += [ - path(r'admin/webhook-backend-status/', include('django_rq.urls')), - ] - if settings.DEBUG: import debug_toolbar _patterns += [ diff --git a/requirements.txt b/requirements.txt index 7b923f40f..9a6cf297a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ Pillow==6.2.0 psycopg2-binary==2.8.3 py-gfm==0.1.4 pycryptodome==3.8.2 +redis==3.3.11