14132 fix webhook_worker

This commit is contained in:
Arthur 2023-11-01 10:34:55 -07:00
parent 7770637e3a
commit 7cb704db47
3 changed files with 20 additions and 20 deletions

View File

@ -42,11 +42,11 @@ def module_member(name):
return getattr(module, member)
def process_event_rules(event_rule, model_name, event, data, timestamp, username, request_id):
def process_event_rules(event_rule, model_name, event, data, timestamp, username, request_id, snapshots):
if event_rule.event_type == EventRuleTypeChoices.WEBHOOK:
process_webhook(event_rule, model_name, event, data, timestamp, username, request_id)
process_webhook(event_rule, model_name, event, data, timestamp, username, request_id, snapshots)
elif event_rule.event_type == EventRuleTypeChoicesEventRuleTypeChoices.SCRIPT:
process_script(event_rule, model_name, event, data, timestamp, username, request_id)
process_script(event_rule, model_name, event, data, timestamp, username, request_id, snapshots)
@job('default')
@ -58,21 +58,7 @@ def process_event(event_rule, model_name, event, data, timestamp, username, requ
if not eval_conditions(event_rule, data):
return
# Prepare context data for headers & body templates
context = {
'event': WEBHOOK_EVENT_TYPES[event],
'timestamp': timestamp,
'model': model_name,
'username': username,
'request_id': request_id,
'data': data,
}
if snapshots:
context.update({
'snapshots': snapshots
})
# process the events pipeline
for name in settings.NETBOX_EVENTS_PIPELINE:
func = module_member(name)
func(event_rule, model_name, event, data, timestamp, username, request_id)
func(event_rule, model_name, event, data, timestamp, username, request_id, snapshots)

View File

@ -12,7 +12,7 @@ from .webhooks import generate_signature
logger = logging.getLogger('netbox.webhooks_worker')
def process_script(webhook, model_name, event, data, timestamp, username, request_id=None):
def process_script(webhook, model_name, event, data, timestamp, username, request_id=None, snapshots=None):
"""
Make a POST request to the defined Webhook
"""

View File

@ -12,13 +12,27 @@ from .webhooks import generate_signature
logger = logging.getLogger('netbox.webhooks_worker')
def process_webhook(event_rule, model_name, event, data, timestamp, username, request_id=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
"""
webhook = event_rule.object
# Prepare context data for headers & body templates
context = {
'event': WEBHOOK_EVENT_TYPES[event],
'timestamp': timestamp,
'model': model_name,
'username': username,
'request_id': request_id,
'data': data,
}
if snapshots:
context.update({
'snapshots': snapshots
})
# Build the headers for the HTTP request
headers = {
'Content-Type': webhook.http_content_type,