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

Render the payload_url of the Webhook with Jinja2

- Update markdown documentation
- Expand on the help text for the Webhook model
This commit is contained in:
Martin Rødvand
2022-01-12 21:58:19 +01:00
parent c8713d94d8
commit 5cbc978cad
3 changed files with 12 additions and 5 deletions

View File

@@ -68,7 +68,8 @@ class Webhook(ChangeLoggedModel):
payload_url = models.CharField(
max_length=500,
verbose_name='URL',
help_text="A POST will be sent to this URL when the webhook is called."
help_text='This URL will be called using the HTTP method defined when the webhook is called. '
'Jinja2 template processing is supported with the same context as the request body.'
)
enabled = models.BooleanField(
default=True
@@ -176,6 +177,12 @@ class Webhook(ChangeLoggedModel):
else:
return json.dumps(context, cls=JSONEncoder)
def render_payload_url(self, context):
"""
Render the payload URL.
"""
return render_jinja2(self.payload_url, context)
@extras_features('webhooks', 'export_templates')
class CustomLink(ChangeLoggedModel):

View File

@@ -67,7 +67,7 @@ def process_webhook(webhook, model_name, event, data, snapshots, timestamp, user
# Prepare the HTTP request
params = {
'method': webhook.http_method,
'url': webhook.payload_url,
'url': webhook.render_payload_url(context),
'headers': headers,
'data': body.encode('utf8'),
}