From fe4f4bddc8392a46daddbcd4b6d2350f4846e699 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 18 Mar 2020 13:46:47 -0400 Subject: [PATCH] Tweaked logging; renamed release config parameters --- docs/configuration/optional-settings.md | 36 ++++++++++++------------ netbox/netbox/configuration.example.py | 16 +++++------ netbox/netbox/settings.py | 34 +++++++++++----------- netbox/netbox/tests/test_get_releases.py | 2 +- netbox/utilities/background_tasks.py | 6 ++-- netbox/utilities/releases.py | 8 +++--- 6 files changed, 51 insertions(+), 51 deletions(-) diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index 2a58ad807..83a56d2c4 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -299,6 +299,24 @@ When determining the primary IP address for a device, IPv6 is preferred over IPv --- +## RELEASE_CHECK_TIMEOUT + +Default: 86,400 (24 hours) + +The number of seconds to retain the latest version that is fetched from the GitHub API before automatically invalidating it and fetching it from the API again. This must be set to at least one hour (3600 seconds). + +--- + +## RELEASE_CHECK_URL + +Default: None + +The releases of this repository are checked to detect new releases, which are shown on the home page of the web interface. You can change this to your own fork of the NetBox repository, or set it to `None` to disable the check. The URL provided **must** be compatible with the GitHub API. + +Use `'https://api.github.com/repos/netbox-community/netbox/releases'` to check for release in the official NetBox repository. + +--- + ## REPORTS_ROOT Default: $BASE_DIR/netbox/reports/ @@ -351,24 +369,6 @@ The time zone NetBox will use when dealing with dates and times. It is recommend --- -## UPDATE_CACHE_TIMEOUT - -Default: 86,400 (24 hours) - -The number of seconds to retain the latest version that is fetched from the GitHub API before automatically invalidating it and fetching it from the API again. This must be set to at least one hour (3600 seconds). - ---- - -## UPDATE_REPO_URL - -Default: None - -The releases of this repository are checked to detect new releases, which are shown on the home page of the web interface. You can change this to your own fork of the NetBox repository, or set it to `None` to disable the check. The URL provided **must** be compatible with the GitHub API. - -Use `'https://api.github.com/repos/netbox-community/netbox/releases'` to check for release in the official NetBox repository. - ---- - ## 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/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index be4b4d762..f41c6892a 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -179,6 +179,14 @@ PAGINATE_COUNT = 50 # prefer IPv4 instead. PREFER_IPV4 = False +# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour. +RELEASE_CHECK_TIMEOUT = 24 * 3600 + +# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the +# version check or use the URL below to check for release in the official NetBox repository. +RELEASE_CHECK_URL = None +# RELEASE_CHECK_URL = 'https://api.github.com/repos/netbox-community/netbox/releases' + # The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of # this setting is derived from the installed location. # REPORTS_ROOT = '/opt/netbox/netbox/reports' @@ -195,14 +203,6 @@ SESSION_FILE_PATH = None # Time zone (default: UTC) TIME_ZONE = 'UTC' -# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour. -UPDATE_CACHE_TIMEOUT = 24 * 3600 - -# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the -# version check or use the URL below to check for release in the official NetBox repository. -UPDATE_REPO_URL = None -# UPDATE_REPO_URL = 'https://api.github.com/repos/netbox-community/netbox/releases' - # 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 2f9643c78..7e4e8a1d9 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -97,6 +97,8 @@ NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30) NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '') PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) +RELEASE_CHECK_URL = getattr(configuration, 'RELEASE_CHECK_URL', None) +RELEASE_CHECK_TIMEOUT = getattr(configuration, 'RELEASE_CHECK_TIMEOUT', 24 * 3600) REPORTS_ROOT = getattr(configuration, 'REPORTS_ROOT', os.path.join(BASE_DIR, 'reports')).rstrip('/') SCRIPTS_ROOT = getattr(configuration, 'SCRIPTS_ROOT', os.path.join(BASE_DIR, 'scripts')).rstrip('/') SESSION_FILE_PATH = getattr(configuration, 'SESSION_FILE_PATH', None) @@ -105,22 +107,20 @@ 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') -UPDATE_REPO_URL = getattr(configuration, 'UPDATE_REPO_URL', None) -UPDATE_CACHE_TIMEOUT = getattr(configuration, 'UPDATE_CACHE_TIMEOUT', 24 * 3600) # Validate update repo URL and timeout -if UPDATE_REPO_URL: +if RELEASE_CHECK_URL: try: - URLValidator(UPDATE_REPO_URL) + URLValidator(RELEASE_CHECK_URL) except ValidationError: raise ImproperlyConfigured( - "UPDATE_REPO_URL must be a valid API URL. Example: " + "RELEASE_CHECK_URL must be a valid API URL. Example: " "https://api.github.com/repos/netbox-community/netbox" ) # Enforce a minimum cache timeout for update checks -if UPDATE_CACHE_TIMEOUT < 3600: - raise ImproperlyConfigured("UPDATE_CACHE_TIMEOUT has to be at least 3600 seconds (1 hour)") +if RELEASE_CHECK_TIMEOUT < 3600: + raise ImproperlyConfigured("RELEASE_CHECK_TIMEOUT has to be at least 3600 seconds (1 hour)") # @@ -576,16 +576,7 @@ SWAGGER_SETTINGS = { # Django RQ (Webhooks backend) # -if not TASKS_REDIS_USING_SENTINEL: - RQ_PARAMS = { - 'HOST': TASKS_REDIS_HOST, - 'PORT': TASKS_REDIS_PORT, - 'DB': TASKS_REDIS_DATABASE, - 'PASSWORD': TASKS_REDIS_PASSWORD, - 'DEFAULT_TIMEOUT': TASKS_REDIS_DEFAULT_TIMEOUT, - 'SSL': TASKS_REDIS_SSL, - } -else: +if TASKS_REDIS_USING_SENTINEL: RQ_PARAMS = { 'SENTINELS': TASKS_REDIS_SENTINELS, 'MASTER_NAME': TASKS_REDIS_SENTINEL_SERVICE, @@ -596,6 +587,15 @@ else: 'socket_connect_timeout': TASKS_REDIS_DEFAULT_TIMEOUT }, } +else: + RQ_PARAMS = { + 'HOST': TASKS_REDIS_HOST, + 'PORT': TASKS_REDIS_PORT, + 'DB': TASKS_REDIS_DATABASE, + 'PASSWORD': TASKS_REDIS_PASSWORD, + 'DEFAULT_TIMEOUT': TASKS_REDIS_DEFAULT_TIMEOUT, + 'SSL': TASKS_REDIS_SSL, + } RQ_QUEUES = { 'default': RQ_PARAMS, # Webhooks diff --git a/netbox/netbox/tests/test_get_releases.py b/netbox/netbox/tests/test_get_releases.py index 8d75e4dfc..635a6782b 100644 --- a/netbox/netbox/tests/test_get_releases.py +++ b/netbox/netbox/tests/test_get_releases.py @@ -56,7 +56,7 @@ def unsuccessful_github_response(url, *_args, **_kwargs): return r -@override_settings(UPDATE_REPO_URL='https://localhost/unittest/releases', UPDATE_CACHE_TIMEOUT=160876) +@override_settings(RELEASE_CHECK_URL='https://localhost/unittest/releases', RELEASE_CHECK_TIMEOUT=160876) class GetReleasesTestCase(SimpleTestCase): @patch.object(requests, 'get') @patch.object(RedisCache, 'set') diff --git a/netbox/utilities/background_tasks.py b/netbox/utilities/background_tasks.py index 68eebbcc8..1255846b7 100644 --- a/netbox/utilities/background_tasks.py +++ b/netbox/utilities/background_tasks.py @@ -12,7 +12,7 @@ logger = logging.getLogger('netbox.releases') @job('check_releases') def get_releases(pre_releases=False): - url = settings.UPDATE_REPO_URL + url = settings.RELEASE_CHECK_URL headers = { 'Accept': 'application/vnd.github.v3+json', } @@ -21,7 +21,7 @@ def get_releases(pre_releases=False): # Check whether this URL has failed recently and shouldn't be retried yet try: if url == cache.get('latest_release_no_retry'): - logger.debug("Skipping release check; URL failed recently: {}".format(url)) + logger.info("Skipping release check; URL failed recently: {}".format(url)) return [] except CacheMiss: pass @@ -47,6 +47,6 @@ def get_releases(pre_releases=False): return [] # Cache the most recent release - cache.set('latest_release', max(releases), settings.UPDATE_CACHE_TIMEOUT) + cache.set('latest_release', max(releases), settings.RELEASE_CHECK_TIMEOUT) return releases diff --git a/netbox/utilities/releases.py b/netbox/utilities/releases.py index 841cc8b0c..27279cc16 100644 --- a/netbox/utilities/releases.py +++ b/netbox/utilities/releases.py @@ -10,7 +10,7 @@ logger = logging.getLogger('netbox.releases') def get_latest_release(pre_releases=False): - if settings.UPDATE_REPO_URL: + if settings.RELEASE_CHECK_URL: logger.debug("Checking for most recent release") try: latest_release = cache.get('latest_release') @@ -21,13 +21,13 @@ def get_latest_release(pre_releases=False): # Check for an existing job. This can happen if the RQ worker process is not running. queue = get_queue('check_releases') if queue.jobs: - logger.debug("Job to check for new releases is already queued; skipping") + logger.warning("Job to check for new releases is already queued; skipping") else: # Get the releases in the background worker, it will fill the cache - logger.debug("Initiating background task to retrieve updated releases list") + logger.info("Initiating background task to retrieve updated releases list") get_releases.delay(pre_releases=pre_releases) else: - logger.debug("Skipping release check; UPDATE_REPO_URL not defined") + logger.debug("Skipping release check; RELEASE_CHECK_URL not defined") return 'unknown', None