mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Render Action Data as Jinja2
This commit is contained in:
parent
b408beaed5
commit
4de5046109
@ -119,13 +119,22 @@ def process_event_rules(event_rules, model_name, event, data, username=None, sna
|
||||
script_name = event_rule.action_parameters['script_name']
|
||||
script = script_module.scripts[script_name]()
|
||||
|
||||
context = {
|
||||
'event': event,
|
||||
'timestamp': timezone.now().isoformat(),
|
||||
'model': model_name,
|
||||
'username': username,
|
||||
'request_id': request_id,
|
||||
'model': data,
|
||||
}
|
||||
|
||||
# Enqueue a Job to record the script's execution
|
||||
Job.enqueue(
|
||||
"extras.scripts.run_script",
|
||||
instance=script_module,
|
||||
name=script.class_name,
|
||||
user=user,
|
||||
data=data
|
||||
data=event_rule.render_script_data(context)
|
||||
)
|
||||
|
||||
else:
|
||||
|
@ -171,6 +171,15 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
||||
return True
|
||||
|
||||
return ConditionSet(self.conditions).eval(data)
|
||||
|
||||
def render_script_data(self, context):
|
||||
"""
|
||||
Render Script Data, if defined. Otherwise, jump the context as a JSON object.
|
||||
"""
|
||||
if self.action_data:
|
||||
return render_jinja2(str(self.action_data), context)
|
||||
else:
|
||||
return json.dumps(context, cls=JSONEncoder)
|
||||
|
||||
|
||||
class Webhook(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLoggedModel):
|
||||
|
Loading…
Reference in New Issue
Block a user