Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions netbox/extras/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ def get_action_object(self, instance):
# We need to manually instantiate the serializer for scripts
if instance.action_type == EventRuleActionChoices.SCRIPT:
script_name = instance.action_parameters['script_name']
script = instance.action_object.scripts[script_name]()
return NestedScriptSerializer(script, context=context).data
if script_name in instance.action_object.scripts:
script = instance.action_object.scripts[script_name]()
return NestedScriptSerializer(script, context=context).data
else:
return None
else:
serializer = get_serializer_for_model(
model=instance.action_object_type.model_class(),
Expand Down
8 changes: 8 additions & 0 deletions netbox/extras/models/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
from functools import cached_property

from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -41,6 +42,13 @@ class ScriptModule(PythonModuleMixin, JobsMixin, ManagedFile):
"""
objects = ScriptModuleManager()

event_rules = GenericRelation(
to='extras.EventRule',
content_type_field='action_object_type',
object_id_field='action_object_id',
for_concrete_model=False
)

class Meta:
proxy = True
verbose_name = _('script module')
Expand Down