From 2b154dcfdf45f1e678c879b8062afe12f2062ef0 Mon Sep 17 00:00:00 2001 From: Nick Niehoff Date: Thu, 29 Oct 2020 15:14:52 -0600 Subject: [PATCH 1/2] Fixing #5282 - moving logging configuration from authentication.py to configuration.py --- docs/installation/6-ldap.md | 28 ++++++++++++++++++++-------- netbox/netbox/authentication.py | 5 ----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/docs/installation/6-ldap.md b/docs/installation/6-ldap.md index bb1300c08..47093b2c1 100644 --- a/docs/installation/6-ldap.md +++ b/docs/installation/6-ldap.md @@ -143,17 +143,29 @@ AUTH_LDAP_CACHE_TIMEOUT = 3600 `systemctl restart netbox` restarts the Netbox service, and initiates any changes made to `ldap_config.py`. If there are syntax errors present, the NetBox process will not spawn an instance, and errors should be logged to `/var/log/messages`. -For troubleshooting LDAP user/group queries, add the following lines to the start of `ldap_config.py` after `import ldap`. +For troubleshooting LDAP user/group queries, add or merge the following [logging](/configuration/optional-settings.md#logging) configuration to `configuration.py`: ```python -import logging, logging.handlers logfile = "/opt/netbox/logs/django-ldap-debug.log" -my_logger = logging.getLogger('django_auth_ldap') -my_logger.setLevel(logging.DEBUG) -handler = logging.handlers.RotatingFileHandler( - logfile, maxBytes=1024 * 500, backupCount=5 -) -my_logger.addHandler(handler) +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "handlers": { + 'netbox_auth_log': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': logfile, + 'maxBytes': 1024 * 500, + 'backupCount': 5, + }, + }, + 'loggers': { + 'django_auth_ldap': { + 'handlers': ['netbox_auth_log'], + 'level': 'DEBUG', + }, + }, +} ``` Ensure the file and path specified in logfile exist and are writable and executable by the application service account. Restart the netbox service and attempt to log into the site to trigger log entries to this file. diff --git a/netbox/netbox/authentication.py b/netbox/netbox/authentication.py index 6328c40d7..21fb3e229 100644 --- a/netbox/netbox/authentication.py +++ b/netbox/netbox/authentication.py @@ -172,9 +172,4 @@ class LDAPBackend: if getattr(ldap_config, 'LDAP_IGNORE_CERT_ERRORS', False): ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER) - # Enable logging for django_auth_ldap - ldap_logger = logging.getLogger('django_auth_ldap') - ldap_logger.addHandler(logging.StreamHandler()) - ldap_logger.setLevel(logging.INFO) - return obj From 97ea15e978344c05c7257432b5fd340e66f6b93c Mon Sep 17 00:00:00 2001 From: Nick Niehoff Date: Fri, 30 Oct 2020 06:32:12 -0600 Subject: [PATCH 2/2] Removing logfile variable --- docs/installation/6-ldap.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/installation/6-ldap.md b/docs/installation/6-ldap.md index 47093b2c1..b7d525413 100644 --- a/docs/installation/6-ldap.md +++ b/docs/installation/6-ldap.md @@ -146,15 +146,14 @@ AUTH_LDAP_CACHE_TIMEOUT = 3600 For troubleshooting LDAP user/group queries, add or merge the following [logging](/configuration/optional-settings.md#logging) configuration to `configuration.py`: ```python -logfile = "/opt/netbox/logs/django-ldap-debug.log" LOGGING = { - "version": 1, - "disable_existing_loggers": False, - "handlers": { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { 'netbox_auth_log': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', - 'filename': logfile, + 'filename': '/opt/netbox/logs/django-ldap-debug.log', 'maxBytes': 1024 * 500, 'backupCount': 5, },