mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 13:38:16 -06:00
14132 fix runscript
This commit is contained in:
parent
3dbdd47ada
commit
48ed7cc91d
@ -282,7 +282,7 @@ class EventRuleForm(NetBoxModelForm):
|
||||
for module in ScriptModule.objects.all():
|
||||
scripts = []
|
||||
for script_name in module.scripts.keys():
|
||||
name = f"{str(module.pk)}:{script_name.lower()}"
|
||||
name = f"{str(module.pk)}:{script_name}"
|
||||
scripts.append((name, script_name))
|
||||
|
||||
if scripts:
|
||||
|
@ -472,7 +472,7 @@ def get_module_and_script(module_name, script_name):
|
||||
return module, script
|
||||
|
||||
|
||||
def run_script(data, request, job, commit=True, **kwargs):
|
||||
def run_script(data, job, request=None, commit=True, **kwargs):
|
||||
"""
|
||||
A wrapper for calling Script.run(). This performs error handling and provides a hook for committing changes. It
|
||||
exists outside the Script class to ensure it cannot be overridden by a script author.
|
||||
@ -486,9 +486,10 @@ def run_script(data, request, job, commit=True, **kwargs):
|
||||
logger.info(f"Running script (commit={commit})")
|
||||
|
||||
# Add files to form data
|
||||
files = request.FILES
|
||||
for field_name, fileobj in files.items():
|
||||
data[field_name] = fileobj
|
||||
if request:
|
||||
files = request.FILES
|
||||
for field_name, fileobj in files.items():
|
||||
data[field_name] = fileobj
|
||||
|
||||
# Add the current request as a property of the script
|
||||
script.request = request
|
||||
|
@ -10,6 +10,7 @@ from utilities.rqworker import get_workers_for_queue
|
||||
from extras.conditions import ConditionSet
|
||||
from extras.constants import WEBHOOK_EVENT_TYPES
|
||||
from extras.models import ScriptModule
|
||||
from extras.scripts import run_script
|
||||
from extras.webhooks import generate_signature
|
||||
|
||||
logger = logging.getLogger('netbox.webhooks_worker')
|
||||
@ -19,13 +20,15 @@ def process_script(event_rule, model_name, event, data, timestamp, username, req
|
||||
"""
|
||||
Run the requested script
|
||||
"""
|
||||
module_name = event_rule.action_object_identifier.split(":")[0]
|
||||
module_id = event_rule.action_object_identifier.split(":")[0]
|
||||
script_name = event_rule.action_object_identifier.split(":")[1]
|
||||
|
||||
try:
|
||||
module = ScriptModule.objects.get(file_path__regex=f"^{module_name}\\.")
|
||||
module = ScriptModule.objects.get(pk=module_id)
|
||||
except ScriptModule.DoesNotExist:
|
||||
return
|
||||
|
||||
# breakpoint()
|
||||
script = module.scripts[script_name]()
|
||||
|
||||
job = Job.enqueue(
|
||||
|
Loading…
Reference in New Issue
Block a user