mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 13:38:16 -06:00
14132 review changes fix tests
This commit is contained in:
parent
56a9210d6c
commit
7eb5371600
@ -3,9 +3,14 @@ import sys
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django_rq import get_queue
|
||||
from django.utils import timezone
|
||||
|
||||
from netbox.config import get_config
|
||||
from netbox.constants import RQ_QUEUE_DEFAULT
|
||||
from netbox.registry import registry
|
||||
from utilities.api import get_serializer_for_model
|
||||
from utilities.rqworker import get_rq_retry
|
||||
from utilities.utils import serialize_object
|
||||
from .choices import *
|
||||
from .models import EventRule
|
||||
|
@ -170,7 +170,6 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
||||
if not self.conditions:
|
||||
return True
|
||||
|
||||
logger.debug(f'Evaluating event rule conditions: {self.conditions}')
|
||||
if ConditionSet(self.conditions).eval(data):
|
||||
return True
|
||||
|
||||
|
@ -1,16 +1,12 @@
|
||||
import logging
|
||||
from django.db.models import Q
|
||||
from django_rq import get_queue
|
||||
from django.utils import timezone
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from taggit.managers import _TaggableManager
|
||||
|
||||
from extras.conditions import ConditionSet
|
||||
from netbox.constants import RQ_QUEUE_DEFAULT
|
||||
from extras.choices import EventRuleActionChoices
|
||||
from netbox.config import get_config
|
||||
from netbox.registry import registry
|
||||
from utilities.rqworker import get_rq_retry
|
||||
|
||||
logger = logging.getLogger('netbox.extras.utils')
|
||||
|
||||
@ -79,37 +75,3 @@ def is_report(obj):
|
||||
return issubclass(obj, Report) and obj != Report
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
|
||||
def process_event_rules(event_rules, model_name, event, data, username, snapshots=None, request_id=None):
|
||||
rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', RQ_QUEUE_DEFAULT)
|
||||
rq_queue = get_queue(rq_queue_name)
|
||||
|
||||
for event_rule in event_rules:
|
||||
if event_rule.action_type == EventRuleActionChoices.WEBHOOK:
|
||||
processor = "extras.webhooks_worker.process_webhook"
|
||||
elif event_rule.action_type == EventRuleActionChoices.SCRIPT:
|
||||
processor = "extras.scripts_worker.process_script"
|
||||
else:
|
||||
raise ValueError(f"Unknown action type for an event rule: {event_rule.action_type}")
|
||||
|
||||
params = {
|
||||
"event_rule": event_rule,
|
||||
"model_name": model_name,
|
||||
"event": event,
|
||||
"data": data,
|
||||
"snapshots": snapshots,
|
||||
"timestamp": str(timezone.now()),
|
||||
"username": username,
|
||||
"retry": get_rq_retry()
|
||||
}
|
||||
|
||||
if snapshots:
|
||||
params["snapshots"] = snapshots
|
||||
if request_id:
|
||||
params["request_id"] = request_id
|
||||
|
||||
rq_queue.enqueue(
|
||||
processor,
|
||||
**params
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user