1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

14132 Add EventRule - change webhook and add in script processing to events (#14267)

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Arthur Hanson
2023-11-30 13:36:33 -08:00
committed by GitHub
parent b83fcc6077
commit a38a38218b
55 changed files with 1569 additions and 589 deletions

View File

@ -5,36 +5,18 @@ from django.conf import settings
from django_rq import job
from jinja2.exceptions import TemplateError
from .conditions import ConditionSet
from .constants import WEBHOOK_EVENT_TYPES
from .webhooks import generate_signature
logger = logging.getLogger('netbox.webhooks_worker')
def eval_conditions(webhook, data):
"""
Test whether the given data meets the conditions of the webhook (if any). Return True
if met or no conditions are specified.
"""
if not webhook.conditions:
return True
logger.debug(f'Evaluating webhook conditions: {webhook.conditions}')
if ConditionSet(webhook.conditions).eval(data):
return True
return False
@job('default')
def process_webhook(webhook, model_name, event, data, timestamp, username, request_id=None, snapshots=None):
def process_webhook(event_rule, model_name, event, data, timestamp, username, request_id=None, snapshots=None):
"""
Make a POST request to the defined Webhook
"""
# Evaluate webhook conditions (if any)
if not eval_conditions(webhook, data):
return
webhook = event_rule.action_object
# Prepare context data for headers & body templates
context = {