mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Add http_method field to Webhook
This commit is contained in:
parent
9a532b1eb2
commit
211311be9f
@ -47,16 +47,24 @@ class WebhookAdmin(admin.ModelAdmin):
|
|||||||
form = WebhookForm
|
form = WebhookForm
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('name', 'obj_type', 'enabled')
|
'fields': (
|
||||||
|
'name', 'obj_type', 'enabled',
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
('Events', {
|
('Events', {
|
||||||
'fields': ('type_create', 'type_update', 'type_delete')
|
'fields': (
|
||||||
|
'type_create', 'type_update', 'type_delete',
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
('HTTP Request', {
|
('HTTP Request', {
|
||||||
'fields': ('payload_url', 'http_content_type', 'additional_headers', 'body_template', 'secret')
|
'fields': (
|
||||||
|
'http_method', 'payload_url', 'http_content_type', 'additional_headers', 'body_template', 'secret',
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
('SSL', {
|
('SSL', {
|
||||||
'fields': ('ssl_verification', 'ca_file_path')
|
'fields': (
|
||||||
|
'ssl_verification', 'ca_file_path',
|
||||||
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -118,3 +118,24 @@ class TemplateLanguageChoices(ChoiceSet):
|
|||||||
LANGUAGE_DJANGO: 10,
|
LANGUAGE_DJANGO: 10,
|
||||||
LANGUAGE_JINJA2: 20,
|
LANGUAGE_JINJA2: 20,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Webhooks
|
||||||
|
#
|
||||||
|
|
||||||
|
class WebhookHttpMethodChoices(ChoiceSet):
|
||||||
|
|
||||||
|
METHOD_GET = 'GET'
|
||||||
|
METHOD_POST = 'POST'
|
||||||
|
METHOD_PUT = 'PUT'
|
||||||
|
METHOD_PATCH = 'PATCH'
|
||||||
|
METHOD_DELETE = 'DELETE'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(METHOD_GET, 'GET'),
|
||||||
|
(METHOD_POST, 'POST'),
|
||||||
|
(METHOD_PUT, 'PUT'),
|
||||||
|
(METHOD_PATCH, 'PATCH'),
|
||||||
|
(METHOD_DELETE, 'DELETE'),
|
||||||
|
)
|
||||||
|
@ -21,6 +21,11 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='webhook',
|
||||||
|
name='http_method',
|
||||||
|
field=models.CharField(default='POST', max_length=30),
|
||||||
|
),
|
||||||
migrations.AddField(
|
migrations.AddField(
|
||||||
model_name='webhook',
|
model_name='webhook',
|
||||||
name='body_template',
|
name='body_template',
|
||||||
|
@ -85,6 +85,12 @@ class Webhook(models.Model):
|
|||||||
enabled = models.BooleanField(
|
enabled = models.BooleanField(
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
|
http_method = models.CharField(
|
||||||
|
max_length=30,
|
||||||
|
choices=WebhookHttpMethodChoices,
|
||||||
|
default=WebhookHttpMethodChoices.METHOD_POST,
|
||||||
|
verbose_name='HTTP method'
|
||||||
|
)
|
||||||
http_content_type = models.CharField(
|
http_content_type = models.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
default=HTTP_CONTENT_TYPE_JSON,
|
default=HTTP_CONTENT_TYPE_JSON,
|
||||||
|
@ -43,13 +43,15 @@ def process_webhook(webhook, data, model_name, event, timestamp, username, reque
|
|||||||
|
|
||||||
# Prepare the HTTP request
|
# Prepare the HTTP request
|
||||||
params = {
|
params = {
|
||||||
'method': 'POST',
|
'method': webhook.http_method,
|
||||||
'url': webhook.payload_url,
|
'url': webhook.payload_url,
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
'data': body,
|
'data': body,
|
||||||
}
|
}
|
||||||
logger.info(
|
logger.info(
|
||||||
"Sending webhook to {}: {} {}".format(params['url'], context['model'], context['event'])
|
"Sending {} request to {} ({} {})".format(
|
||||||
|
params['method'], params['url'], context['model'], context['event']
|
||||||
|
)
|
||||||
)
|
)
|
||||||
logger.debug(params)
|
logger.debug(params)
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user