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

Add trigger_webhooks() to JobResult

This commit is contained in:
jeremystretch
2023-02-28 16:21:01 -05:00
committed by Jeremy Stretch
parent a8c331f88a
commit 4de64d783e
3 changed files with 56 additions and 12 deletions

View File

@ -5,8 +5,8 @@ from django.conf import settings
from django_rq import job
from jinja2.exceptions import TemplateError
from .choices import ObjectChangeActionChoices
from .conditions import ConditionSet
from .constants import WEBHOOK_EVENT_TYPES
from .webhooks import generate_signature
logger = logging.getLogger('netbox.webhooks_worker')
@ -28,7 +28,7 @@ def eval_conditions(webhook, data):
@job('default')
def process_webhook(webhook, model_name, event, data, snapshots, timestamp, username, request_id):
def process_webhook(webhook, model_name, event, data, timestamp, username, request_id=None, snapshots=None):
"""
Make a POST request to the defined Webhook
"""
@ -38,14 +38,17 @@ def process_webhook(webhook, model_name, event, data, snapshots, timestamp, user
# Prepare context data for headers & body templates
context = {
'event': dict(ObjectChangeActionChoices)[event].lower(),
'event': WEBHOOK_EVENT_TYPES[event],
'timestamp': timestamp,
'model': model_name,
'username': username,
'request_id': request_id,
'data': data,
'snapshots': snapshots,
}
if snapshots:
context.update({
'snapshots': snapshots
})
# Build the headers for the HTTP request
headers = {