A webhook is a mechanism for conveying to some external system a change that took place in NetBox. For example, you may want to notify a monitoring system whenever a device status is changed in NetBox. This can be done by creating a webhook for the device model in NetBox. When NetBox detects a change to a device, an HTTP request containing the details of the change and who made it be sent to the specified receiver. Webhooks are configured in the admin UI under Extras > Webhooks.
Content-Type header. (Defaults to application/json)Name: Value. Jinja2 templating is supported for this field (see below).application/json, this will be formatted as a JSON object.)X-Hook-Signature header to the request, consisting of a HMAC (SHA-512) hex digest of the request body using the secret as the key.Jinja2 templating is supported for the additional_headers and body_template fields. This enables the user to convey change data in the request headers as well as to craft a customized request body. Request content can be crafted to enable the direct interaction with external systems by ensuring the outgoing message is in a format the receiver expects and understands.
For example, you might create a NetBox webhook to trigger a Slack message any time an IP address is created. You can accomplish this using the following configuration:
application/json{"text": "IP address {{ data['address'] }} was created by {{ username }}!"}The following data is available as context for Jinja2 templates:
event - The type of event which triggered the webhook: created, updated, or deleted.model - The NetBox model which triggered the change.timestamp - The time at which the event occurred (in ISO 8601 format).username - The name of the user account associated with the change.request_id - The unique request ID. This may be used to correlate multiple changes associated with a single request.data - A serialized representation of the object after the change was made. This is typically equivalent to the model's representation in NetBox's REST API.If no body template is specified, the request body will be populated with a JSON object containing the context data. For example, a newly created site might appear as follows:
{
"event": "created",
"timestamp": "2020-02-25 15:10:26.010582+00:00",
"model": "site",
"username": "jstretch",
"request_id": "fdbca812-3142-4783-b364-2e2bd5c16c6a",
"data": {
"id": 19,
"name": "Site 1",
"slug": "site-1",
"status":
"value": "active",
"label": "Active",
"id": 1
},
"region": null,
...
}
}
When a change is detected, any resulting webhooks are placed into a Redis queue for processing. This allows the user's request to complete without needing to wait for the outgoing webhook(s) to be processed. The webhooks are then extracted from the queue by the rqworker process and HTTP requests are sent to their respective destinations. The current webhook queue and any failed webhooks can be inspected in the admin UI under Django RQ > Queues.
A request is considered successful if the response has a 2XX status code; otherwise, the request is marked as having failed. Failed requests may be retried manually via the admin UI.