mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
implements #3025 - Add request ID to outbound webhook requests
This commit is contained in:
parent
2170eedf08
commit
2e1887eb0e
@ -4,6 +4,7 @@ v2.5.9 (FUTURE)
|
|||||||
|
|
||||||
* [#2933](https://github.com/digitalocean/netbox/issues/2933) - Add username to outbound webhook requests
|
* [#2933](https://github.com/digitalocean/netbox/issues/2933) - Add username to outbound webhook requests
|
||||||
* [#3011](https://github.com/digitalocean/netbox/issues/3011) - Add SSL support for django-rq (requires django-rq v1.3.1+)
|
* [#3011](https://github.com/digitalocean/netbox/issues/3011) - Add SSL support for django-rq (requires django-rq v1.3.1+)
|
||||||
|
* [#3025](https://github.com/digitalocean/netbox/issues/3025) - Add request ID to outbound webhook requests (for correlating all changes part of a single request)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ def _record_object_deleted(request, instance, **kwargs):
|
|||||||
if hasattr(instance, 'log_change'):
|
if hasattr(instance, 'log_change'):
|
||||||
instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
|
instance.log_change(request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
|
||||||
|
|
||||||
enqueue_webhooks(instance, request.user, OBJECTCHANGE_ACTION_DELETE)
|
enqueue_webhooks(instance, request.user, request.id, OBJECTCHANGE_ACTION_DELETE)
|
||||||
|
|
||||||
|
|
||||||
class ObjectChangeMiddleware(object):
|
class ObjectChangeMiddleware(object):
|
||||||
@ -83,7 +83,7 @@ class ObjectChangeMiddleware(object):
|
|||||||
obj.log_change(request.user, request.id, action)
|
obj.log_change(request.user, request.id, action)
|
||||||
|
|
||||||
# Enqueue webhooks
|
# Enqueue webhooks
|
||||||
enqueue_webhooks(obj, request.user, action)
|
enqueue_webhooks(obj, request.user, request.id, action)
|
||||||
|
|
||||||
# Housekeeping: 1% chance of clearing out expired ObjectChanges
|
# Housekeeping: 1% chance of clearing out expired ObjectChanges
|
||||||
if _thread_locals.changed_objects and settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:
|
if _thread_locals.changed_objects and settings.CHANGELOG_RETENTION and random.randint(1, 100) == 1:
|
||||||
|
@ -9,7 +9,7 @@ from utilities.api import get_serializer_for_model
|
|||||||
from .constants import WEBHOOK_MODELS
|
from .constants import WEBHOOK_MODELS
|
||||||
|
|
||||||
|
|
||||||
def enqueue_webhooks(instance, user, action):
|
def enqueue_webhooks(instance, user, request_id, action):
|
||||||
"""
|
"""
|
||||||
Find Webhook(s) assigned to this instance + action and enqueue them
|
Find Webhook(s) assigned to this instance + action and enqueue them
|
||||||
to be processed
|
to be processed
|
||||||
@ -48,5 +48,6 @@ def enqueue_webhooks(instance, user, action):
|
|||||||
instance._meta.model_name,
|
instance._meta.model_name,
|
||||||
action,
|
action,
|
||||||
str(datetime.datetime.now()),
|
str(datetime.datetime.now()),
|
||||||
user.username
|
user.username,
|
||||||
|
request_id
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJ
|
|||||||
|
|
||||||
|
|
||||||
@job('default')
|
@job('default')
|
||||||
def process_webhook(webhook, data, model_name, event, timestamp, username):
|
def process_webhook(webhook, data, model_name, event, timestamp, username, request_id):
|
||||||
"""
|
"""
|
||||||
Make a POST request to the defined Webhook
|
Make a POST request to the defined Webhook
|
||||||
"""
|
"""
|
||||||
@ -19,6 +19,7 @@ def process_webhook(webhook, data, model_name, event, timestamp, username):
|
|||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'model': model_name,
|
'model': model_name,
|
||||||
'username': username,
|
'username': username,
|
||||||
|
'request_id': request_id,
|
||||||
'data': data
|
'data': data
|
||||||
}
|
}
|
||||||
headers = {
|
headers = {
|
||||||
|
Loading…
Reference in New Issue
Block a user