mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
14132 change_logging -> event_logging
This commit is contained in:
parent
edc4a35296
commit
ee913e1f91
@ -5,7 +5,7 @@ from .webhooks import flush_webhooks
|
|||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def change_logging(request):
|
def event_logging(request):
|
||||||
"""
|
"""
|
||||||
Enable change logging by connecting the appropriate signals to their receivers before code is run, and
|
Enable change logging by connecting the appropriate signals to their receivers before code is run, and
|
||||||
disconnecting them afterward.
|
disconnecting them afterward.
|
||||||
|
@ -11,7 +11,7 @@ from django.db import transaction
|
|||||||
from core.choices import JobStatusChoices
|
from core.choices import JobStatusChoices
|
||||||
from core.models import Job
|
from core.models import Job
|
||||||
from extras.api.serializers import ScriptOutputSerializer
|
from extras.api.serializers import ScriptOutputSerializer
|
||||||
from extras.context_managers import change_logging
|
from extras.context_managers import event_logging
|
||||||
from extras.scripts import get_module_and_script
|
from extras.scripts import get_module_and_script
|
||||||
from extras.signals import clear_webhooks
|
from extras.signals import clear_webhooks
|
||||||
from utilities.exceptions import AbortTransaction
|
from utilities.exceptions import AbortTransaction
|
||||||
@ -37,7 +37,7 @@ class Command(BaseCommand):
|
|||||||
def _run_script():
|
def _run_script():
|
||||||
"""
|
"""
|
||||||
Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with
|
Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with
|
||||||
the change_logging context manager (which is bypassed if commit == False).
|
the event_logging context manager (which is bypassed if commit == False).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@ -136,9 +136,9 @@ class Command(BaseCommand):
|
|||||||
logger.info(f"Running script (commit={commit})")
|
logger.info(f"Running script (commit={commit})")
|
||||||
script.request = request
|
script.request = request
|
||||||
|
|
||||||
# Execute the script. If commit is True, wrap it with the change_logging context manager to ensure we process
|
# Execute the script. If commit is True, wrap it with the event_logging context manager to ensure we process
|
||||||
# change logging, webhooks, etc.
|
# change logging, webhooks, etc.
|
||||||
with change_logging(request):
|
with event_logging(request):
|
||||||
_run_script()
|
_run_script()
|
||||||
else:
|
else:
|
||||||
logger.error('Data is not valid:')
|
logger.error('Data is not valid:')
|
||||||
|
@ -23,7 +23,7 @@ from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator,
|
|||||||
from utilities.exceptions import AbortScript, AbortTransaction
|
from utilities.exceptions import AbortScript, AbortTransaction
|
||||||
from utilities.forms import add_blank_choice
|
from utilities.forms import add_blank_choice
|
||||||
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField
|
||||||
from .context_managers import change_logging
|
from .context_managers import event_logging
|
||||||
from .forms import ScriptForm
|
from .forms import ScriptForm
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -496,7 +496,7 @@ def run_script(data, request, job, commit=True, **kwargs):
|
|||||||
def _run_script():
|
def _run_script():
|
||||||
"""
|
"""
|
||||||
Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with
|
Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with
|
||||||
the change_logging context manager (which is bypassed if commit == False).
|
the event_logging context manager (which is bypassed if commit == False).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
@ -524,10 +524,10 @@ def run_script(data, request, job, commit=True, **kwargs):
|
|||||||
|
|
||||||
logger.info(f"Script completed in {job.duration}")
|
logger.info(f"Script completed in {job.duration}")
|
||||||
|
|
||||||
# Execute the script. If commit is True, wrap it with the change_logging context manager to ensure we process
|
# Execute the script. If commit is True, wrap it with the event_logging context manager to ensure we process
|
||||||
# change logging, webhooks, etc.
|
# change logging, webhooks, etc.
|
||||||
if commit:
|
if commit:
|
||||||
with change_logging(request):
|
with event_logging(request):
|
||||||
_run_script()
|
_run_script()
|
||||||
else:
|
else:
|
||||||
_run_script()
|
_run_script()
|
||||||
|
@ -10,7 +10,7 @@ from django.db import connection, ProgrammingError
|
|||||||
from django.db.utils import InternalError
|
from django.db.utils import InternalError
|
||||||
from django.http import Http404, HttpResponseRedirect
|
from django.http import Http404, HttpResponseRedirect
|
||||||
|
|
||||||
from extras.context_managers import change_logging
|
from extras.context_managers import event_logging
|
||||||
from netbox.config import clear_config, get_config
|
from netbox.config import clear_config, get_config
|
||||||
from netbox.views import handler_500
|
from netbox.views import handler_500
|
||||||
from utilities.api import is_api_request, rest_api_server_error
|
from utilities.api import is_api_request, rest_api_server_error
|
||||||
@ -42,8 +42,8 @@ class CoreMiddleware:
|
|||||||
login_url = f'{settings.LOGIN_URL}?next={parse.quote(request.get_full_path_info())}'
|
login_url = f'{settings.LOGIN_URL}?next={parse.quote(request.get_full_path_info())}'
|
||||||
return HttpResponseRedirect(login_url)
|
return HttpResponseRedirect(login_url)
|
||||||
|
|
||||||
# Enable the change_logging context manager and process the request.
|
# Enable the event_logging context manager and process the request.
|
||||||
with change_logging(request):
|
with event_logging(request):
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
|
|
||||||
# Attach the unique request ID as an HTTP header.
|
# Attach the unique request ID as an HTTP header.
|
||||||
|
Loading…
Reference in New Issue
Block a user