diff --git a/netbox/extras/context_managers.py b/netbox/extras/context_managers.py index dc4d3dd17..711a2067a 100644 --- a/netbox/extras/context_managers.py +++ b/netbox/extras/context_managers.py @@ -5,9 +5,9 @@ from .events import flush_events @contextmanager -def event_wrapper(request): +def event_tracking(request): """ - Enable change logging by connecting the appropriate signals to their receivers before code is run, and + Enable event tracking by connecting the appropriate signals to their receivers before code is run, and disconnecting them afterward. :param request: WSGIRequest object with a unique `id` set diff --git a/netbox/extras/management/commands/runscript.py b/netbox/extras/management/commands/runscript.py index c801441b2..5a5e0287e 100644 --- a/netbox/extras/management/commands/runscript.py +++ b/netbox/extras/management/commands/runscript.py @@ -11,7 +11,7 @@ from django.db import transaction from core.choices import JobStatusChoices from core.models import Job from extras.api.serializers import ScriptOutputSerializer -from extras.context_managers import event_wrapper +from extras.context_managers import event_tracking from extras.scripts import get_module_and_script from extras.signals import clear_webhooks from utilities.exceptions import AbortTransaction @@ -37,7 +37,7 @@ class Command(BaseCommand): def _run_script(): """ Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with - the event_wrapper context manager (which is bypassed if commit == False). + the event_tracking context manager (which is bypassed if commit == False). """ try: try: @@ -136,9 +136,9 @@ class Command(BaseCommand): logger.info(f"Running script (commit={commit})") script.request = request - # Execute the script. If commit is True, wrap it with the event_wrapper context manager to ensure we process + # Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process # change logging, webhooks, etc. - with event_wrapper(request): + with event_tracking(request): _run_script() else: logger.error('Data is not valid:') diff --git a/netbox/extras/migrations/0099_eventrule.py b/netbox/extras/migrations/0099_eventrule.py index cb4f2069d..1b5648d36 100644 --- a/netbox/extras/migrations/0099_eventrule.py +++ b/netbox/extras/migrations/0099_eventrule.py @@ -75,8 +75,8 @@ class Migration(migrations.Migration): to='contenttypes.contenttype', ), ), - ('action_object_identifier', models.CharField(max_length=80, blank=True)), - ('parameters', models.JSONField(blank=True, null=True)), + ('action_parameters', models.CharField(max_length=80, blank=True)), + ('action_data', models.JSONField(blank=True, null=True)), ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')), ], options={ diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 5fb53db6b..c37a6ff87 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -115,11 +115,11 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged fk_field='action_object_id' ) # internal (not show in UI) - used by scripts to store function name - action_object_identifier = models.CharField( + action_parameters = models.CharField( max_length=80, blank=True ) - parameters = models.JSONField( + action_data = models.JSONField( verbose_name=_('parameters'), blank=True, null=True, @@ -137,10 +137,6 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged def get_absolute_url(self): return reverse('extras:eventrule', args=[self.pk]) - @property - def docs_url(self): - return f'{settings.STATIC_URL}docs/models/extras/eventrule/' - def clean(self): super().clean() diff --git a/netbox/extras/scripts.py b/netbox/extras/scripts.py index 969257e18..0310b9973 100644 --- a/netbox/extras/scripts.py +++ b/netbox/extras/scripts.py @@ -23,7 +23,7 @@ from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, from utilities.exceptions import AbortScript, AbortTransaction from utilities.forms import add_blank_choice from utilities.forms.fields import DynamicModelChoiceField, DynamicModelMultipleChoiceField -from .context_managers import event_wrapper +from .context_managers import event_tracking from .forms import ScriptForm __all__ = ( @@ -497,7 +497,7 @@ def run_script(data, job, request=None, commit=True, **kwargs): def _run_script(): """ Core script execution task. We capture this within a subfunction to allow for conditionally wrapping it with - the event_wrapper context manager (which is bypassed if commit == False). + the event_tracking context manager (which is bypassed if commit == False). """ try: try: @@ -525,10 +525,10 @@ def run_script(data, job, request=None, commit=True, **kwargs): logger.info(f"Script completed in {job.duration}") - # Execute the script. If commit is True, wrap it with the event_wrapper context manager to ensure we process + # Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process # change logging, webhooks, etc. if commit: - with event_wrapper(request): + with event_tracking(request): _run_script() else: _run_script() diff --git a/netbox/extras/scripts_worker.py b/netbox/extras/scripts_worker.py index 67715ad16..49ab425ec 100644 --- a/netbox/extras/scripts_worker.py +++ b/netbox/extras/scripts_worker.py @@ -24,8 +24,8 @@ def process_script(event_rule, model_name, event, data, timestamp, username, req if not eval_conditions(event_rule, data): return - module_id = event_rule.action_object_identifier.split(":")[0] - script_name = event_rule.action_object_identifier.split(":")[1] + module_id = event_rule.action_parameters.split(":")[0] + script_name = event_rule.action_parameters.split(":")[1] try: module = ScriptModule.objects.get(pk=module_id) @@ -41,5 +41,5 @@ def process_script(event_rule, model_name, event, data, timestamp, username, req user=None, schedule_at=None, interval=None, - data=event_rule.parameters, + data=event_rule.action_data, ) diff --git a/netbox/netbox/middleware.py b/netbox/netbox/middleware.py index 37cb041db..cb7d2c8ba 100644 --- a/netbox/netbox/middleware.py +++ b/netbox/netbox/middleware.py @@ -10,7 +10,7 @@ from django.db import connection, ProgrammingError from django.db.utils import InternalError from django.http import Http404, HttpResponseRedirect -from extras.context_managers import event_wrapper +from extras.context_managers import event_tracking from netbox.config import clear_config, get_config from netbox.views import handler_500 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())}' return HttpResponseRedirect(login_url) - # Enable the event_wrapper context manager and process the request. - with event_wrapper(request): + # Enable the event_tracking context manager and process the request. + with event_tracking(request): response = self.get_response(request) # Attach the unique request ID as an HTTP header.