mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 13:38:16 -06:00
14132 change action_parameters to jsonfield
This commit is contained in:
parent
7eb5371600
commit
568a5b8054
@ -296,7 +296,11 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
choices.append((str(module), scripts))
|
choices.append((str(module), scripts))
|
||||||
|
|
||||||
self.fields['action_choice'].choices = choices
|
self.fields['action_choice'].choices = choices
|
||||||
self.fields['action_choice'].initial = get_field_value(self, 'action_parameters')
|
parameters = get_field_value(self, 'action_parameters')
|
||||||
|
initial = None
|
||||||
|
if parameters and 'script_choice' in parameters:
|
||||||
|
initial = parameters['script_choice']
|
||||||
|
self.fields['action_choice'].initial = initial
|
||||||
|
|
||||||
def init_webhook_choice(self):
|
def init_webhook_choice(self):
|
||||||
initial = None
|
initial = None
|
||||||
@ -331,12 +335,11 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
if self.cleaned_data.get('action_type') == EventRuleActionChoices.WEBHOOK:
|
if self.cleaned_data.get('action_type') == EventRuleActionChoices.WEBHOOK:
|
||||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(action_choice)
|
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(action_choice)
|
||||||
self.cleaned_data['action_object_id'] = action_choice.id
|
self.cleaned_data['action_object_id'] = action_choice.id
|
||||||
self.cleaned_data['action_parameters'] = ''
|
|
||||||
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
|
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
|
||||||
script = ScriptModule.objects.get(pk=action_choice.split(":")[0])
|
script = ScriptModule.objects.get(pk=action_choice.split(":")[0])
|
||||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(script)
|
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(script)
|
||||||
self.cleaned_data['action_object_id'] = script.id
|
self.cleaned_data['action_object_id'] = script.id
|
||||||
self.cleaned_data['action_parameters'] = action_choice
|
self.cleaned_data['action_parameters'] = {'script_choice': action_choice}
|
||||||
|
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class Migration(migrations.Migration):
|
|||||||
('conditions', models.JSONField(blank=True, null=True)),
|
('conditions', models.JSONField(blank=True, null=True)),
|
||||||
('action_type', models.CharField(default='webhook', max_length=30)),
|
('action_type', models.CharField(default='webhook', max_length=30)),
|
||||||
('action_object_id', models.PositiveBigIntegerField(blank=True, null=True)),
|
('action_object_id', models.PositiveBigIntegerField(blank=True, null=True)),
|
||||||
('action_parameters', models.CharField(blank=True, max_length=80)),
|
('action_parameters', models.JSONField(blank=True, null=True)),
|
||||||
('action_data', models.JSONField(blank=True, null=True)),
|
('action_data', models.JSONField(blank=True, null=True)),
|
||||||
('comments', models.TextField(blank=True)),
|
('comments', models.TextField(blank=True)),
|
||||||
],
|
],
|
||||||
|
@ -118,9 +118,9 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
|||||||
fk_field='action_object_id'
|
fk_field='action_object_id'
|
||||||
)
|
)
|
||||||
# internal (not show in UI) - used by scripts to store function name
|
# internal (not show in UI) - used by scripts to store function name
|
||||||
action_parameters = models.CharField(
|
action_parameters = models.JSONField(
|
||||||
max_length=80,
|
blank=True,
|
||||||
blank=True
|
null=True,
|
||||||
)
|
)
|
||||||
action_data = models.JSONField(
|
action_data = models.JSONField(
|
||||||
verbose_name=_('parameters'),
|
verbose_name=_('parameters'),
|
||||||
|
@ -19,8 +19,16 @@ def process_script(event_rule, data, username, **kwargs):
|
|||||||
if not event_rule.eval_conditions(data):
|
if not event_rule.eval_conditions(data):
|
||||||
return
|
return
|
||||||
|
|
||||||
module_id = event_rule.action_parameters.split(":")[0]
|
script_choice = None
|
||||||
script_name = event_rule.action_parameters.split(":")[1]
|
if event_rule.action_parameters and 'script_choice' in event_rule_action_parameters:
|
||||||
|
script_choice = event_rule.action_parameters['script_choice']
|
||||||
|
|
||||||
|
if script_choice:
|
||||||
|
module_id = script_choice.split(":")[0]
|
||||||
|
script_name = script_choice.split(":")[1]
|
||||||
|
else:
|
||||||
|
logger.warning(f"event run script - event_rule: {event_rule.id} no script_choice selected")
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module = ScriptModule.objects.get(pk=module_id)
|
module = ScriptModule.objects.get(pk=module_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user