mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Move CHANGELOG_RETENTION to dyanmic configuration
This commit is contained in:
@ -31,6 +31,18 @@ This defines custom content to be displayed on the login page above the login fo
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## CHANGELOG_RETENTION
|
||||||
|
|
||||||
|
Default: 90
|
||||||
|
|
||||||
|
The number of days to retain logged changes (object creations, updates, and deletions). Set this to `0` to retain
|
||||||
|
changes in the database indefinitely.
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
If enabling indefinite changelog retention, it is recommended to periodically delete old entries. Otherwise, the database may eventually exceed capacity.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ENFORCE_GLOBAL_UNIQUE
|
## ENFORCE_GLOBAL_UNIQUE
|
||||||
|
|
||||||
Default: False
|
Default: False
|
||||||
|
@ -25,18 +25,6 @@ BASE_PATH = 'netbox/'
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## CHANGELOG_RETENTION
|
|
||||||
|
|
||||||
Default: 90
|
|
||||||
|
|
||||||
The number of days to retain logged changes (object creations, updates, and deletions). Set this to `0` to retain
|
|
||||||
changes in the database indefinitely.
|
|
||||||
|
|
||||||
!!! warning
|
|
||||||
If enabling indefinite changelog retention, it is recommended to periodically delete old entries. Otherwise, the database may eventually exceed capacity.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## CORS_ORIGIN_ALLOW_ALL
|
## CORS_ORIGIN_ALLOW_ALL
|
||||||
|
|
||||||
Default: False
|
Default: False
|
||||||
|
@ -31,7 +31,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin):
|
|||||||
'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'),
|
'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'),
|
||||||
}),
|
}),
|
||||||
('Miscellaneous', {
|
('Miscellaneous', {
|
||||||
'fields': ('MAINTENANCE_MODE', 'MAPS_URL'),
|
'fields': ('MAINTENANCE_MODE', 'CHANGELOG_RETENTION', 'MAPS_URL'),
|
||||||
}),
|
}),
|
||||||
('Config Revision', {
|
('Config Revision', {
|
||||||
'fields': ('comment',),
|
'fields': ('comment',),
|
||||||
|
@ -10,12 +10,14 @@ from django.utils import timezone
|
|||||||
from packaging import version
|
from packaging import version
|
||||||
|
|
||||||
from extras.models import ObjectChange
|
from extras.models import ObjectChange
|
||||||
|
from netbox.config import Config
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Perform nightly housekeeping tasks. (This command can be run at any time.)"
|
help = "Perform nightly housekeeping tasks. (This command can be run at any time.)"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
config = Config()
|
||||||
|
|
||||||
# Clear expired authentication sessions (essentially replicating the `clearsessions` command)
|
# Clear expired authentication sessions (essentially replicating the `clearsessions` command)
|
||||||
if options['verbosity']:
|
if options['verbosity']:
|
||||||
@ -37,10 +39,10 @@ class Command(BaseCommand):
|
|||||||
# Delete expired ObjectRecords
|
# Delete expired ObjectRecords
|
||||||
if options['verbosity']:
|
if options['verbosity']:
|
||||||
self.stdout.write("[*] Checking for expired changelog records")
|
self.stdout.write("[*] Checking for expired changelog records")
|
||||||
if settings.CHANGELOG_RETENTION:
|
if config.CHANGELOG_RETENTION:
|
||||||
cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION)
|
cutoff = timezone.now() - timedelta(days=config.CHANGELOG_RETENTION)
|
||||||
if options['verbosity'] >= 2:
|
if options['verbosity'] >= 2:
|
||||||
self.stdout.write(f"\tRetention period: {settings.CHANGELOG_RETENTION} days")
|
self.stdout.write(f"\tRetention period: {config.CHANGELOG_RETENTION} days")
|
||||||
self.stdout.write(f"\tCut-off time: {cutoff}")
|
self.stdout.write(f"\tCut-off time: {cutoff}")
|
||||||
expired_records = ObjectChange.objects.filter(time__lt=cutoff).count()
|
expired_records = ObjectChange.objects.filter(time__lt=cutoff).count()
|
||||||
if expired_records:
|
if expired_records:
|
||||||
@ -58,7 +60,7 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write("\tNo expired records found.", self.style.SUCCESS)
|
self.stdout.write("\tNo expired records found.", self.style.SUCCESS)
|
||||||
elif options['verbosity']:
|
elif options['verbosity']:
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
f"\tSkipping: No retention period specified (CHANGELOG_RETENTION = {settings.CHANGELOG_RETENTION})"
|
f"\tSkipping: No retention period specified (CHANGELOG_RETENTION = {config.CHANGELOG_RETENTION})"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check for new releases (if enabled)
|
# Check for new releases (if enabled)
|
||||||
|
@ -130,6 +130,13 @@ PARAMS = (
|
|||||||
description="Enable maintenance mode",
|
description="Enable maintenance mode",
|
||||||
field=forms.BooleanField
|
field=forms.BooleanField
|
||||||
),
|
),
|
||||||
|
ConfigParam(
|
||||||
|
name='CHANGELOG_RETENTION',
|
||||||
|
label='Changelog retention',
|
||||||
|
default=90,
|
||||||
|
description="Days to retain changelog history (set to zero for unlimited)",
|
||||||
|
field=forms.IntegerField
|
||||||
|
),
|
||||||
ConfigParam(
|
ConfigParam(
|
||||||
name='MAPS_URL',
|
name='MAPS_URL',
|
||||||
label='Maps URL',
|
label='Maps URL',
|
||||||
|
@ -76,9 +76,6 @@ ADMINS = [
|
|||||||
# BASE_PATH = 'netbox/'
|
# BASE_PATH = 'netbox/'
|
||||||
BASE_PATH = ''
|
BASE_PATH = ''
|
||||||
|
|
||||||
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
|
|
||||||
CHANGELOG_RETENTION = 90
|
|
||||||
|
|
||||||
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
|
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
|
||||||
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
|
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
|
||||||
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
|
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
|
||||||
|
@ -80,7 +80,6 @@ ADMINS = getattr(configuration, 'ADMINS', [])
|
|||||||
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
BASE_PATH = getattr(configuration, 'BASE_PATH', '')
|
||||||
if BASE_PATH:
|
if BASE_PATH:
|
||||||
BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only
|
BASE_PATH = BASE_PATH.strip('/') + '/' # Enforce trailing slash only
|
||||||
CHANGELOG_RETENTION = getattr(configuration, 'CHANGELOG_RETENTION', 90)
|
|
||||||
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
CORS_ORIGIN_ALLOW_ALL = getattr(configuration, 'CORS_ORIGIN_ALLOW_ALL', False)
|
||||||
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])
|
CORS_ORIGIN_REGEX_WHITELIST = getattr(configuration, 'CORS_ORIGIN_REGEX_WHITELIST', [])
|
||||||
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
|
CORS_ORIGIN_WHITELIST = getattr(configuration, 'CORS_ORIGIN_WHITELIST', [])
|
||||||
|
Reference in New Issue
Block a user