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

Tweaked logging; renamed release config parameters

This commit is contained in:
Jeremy Stretch
2020-03-18 13:46:47 -04:00
parent 022653f446
commit fe4f4bddc8
6 changed files with 51 additions and 51 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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