1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #3408: Remove WEBHOOKS_ENABLE configuration setting

This commit is contained in:
Jeremy Stretch
2019-12-06 11:52:28 -05:00
parent dd3e7397a4
commit 45917f8014
14 changed files with 39 additions and 90 deletions

View File

@ -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

View File

@ -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).

View File

@ -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
```

View File

@ -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
```

View File

@ -84,15 +84,10 @@ 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
```

View File

@ -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

View File

@ -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."
)

View File

@ -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."
)

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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',

View File

@ -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 += [

View File

@ -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