Pass model object to webhook #3527

Closed
opened 2025-12-29 18:29:39 +01:00 by adam · 7 comments
Owner

Originally created by @andershagman on GitHub (Apr 1, 2020).

Environment

  • Python version: 3.6.x
  • NetBox version: 2.7.x

Proposed Functionality

Change the webhook code to receive the whole model object, not just a serialized stream of json, to be able to manipulate the data with jinja2 in the same manner as with custom links.

Use Case

To be able to pass more correct data to a webhook receiver. Especially if the receiver can not be tampered with.
Ex: from model ipaddress
prefix -> obj.address.network
gateway -> obj.address.network + 1
netmask -> obj.address.netmask
broadcast -> obj.address.broadcast
first address -> obj.address.network + 1
last address -> obj.address.broadcast - 1
dhcp range start -> if obj.address.size > 255 -> obj.address.network + 30
dhcp range end -> obj.address.broadcast - 1

Database Changes

beyond my knowledge

External Dependencies

none

Originally created by @andershagman on GitHub (Apr 1, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.x * NetBox version: 2.7.x <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Change the webhook code to receive the whole model object, not just a serialized stream of json, to be able to manipulate the data with jinja2 in the same manner as with custom links. <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case To be able to pass more correct data to a webhook receiver. Especially if the receiver can not be tampered with. Ex: from model ipaddress prefix -> obj.address.network gateway -> obj.address.network + 1 netmask -> obj.address.netmask broadcast -> obj.address.broadcast first address -> obj.address.network + 1 last address -> obj.address.broadcast - 1 dhcp range start -> if obj.address.size > 255 -> obj.address.network + 30 dhcp range end -> obj.address.broadcast - 1 <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes beyond my knowledge <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies none
adam added the type: featurestatus: needs ownerpending closure labels 2025-12-29 18:29:39 +01:00
adam closed this issue 2025-12-29 18:29:39 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 24, 2020):

I'm not sure this is feasible, given that the model must be serialized for queuing. @lampwins do you have any ideas?

Tagging this as needs owner in case someone wants to volunteer to dig into it more.

@jeremystretch commented on GitHub (Jul 24, 2020): I'm not sure this is feasible, given that the model must be serialized for queuing. @lampwins do you have any ideas? Tagging this as `needs owner` in case someone wants to volunteer to dig into it more.
Author
Owner

@stale[bot] commented on GitHub (Sep 7, 2020):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Sep 7, 2020): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@lampwins commented on GitHub (Sep 14, 2020):

@jeremystretch one thing that comes to mind is to pass the content type and pk into the job and then do a query for the actual object inside the job. This is a common enough pattern and is similar to what we do today with the JobResult instances. If this is something you want to do, I can take it. It should be relatively simple.

@lampwins commented on GitHub (Sep 14, 2020): @jeremystretch one thing that comes to mind is to pass the content type and pk into the job and then do a query for the actual object inside the job. This is a common enough pattern and is similar to what we do today with the JobResult instances. If this is something you want to do, I can take it. It should be relatively simple.
Author
Owner

@jeremystretch commented on GitHub (Sep 14, 2020):

query for the actual object inside the job

I don't think we can make the assumption that the object has not changed between the point in time when the job is queued and the time when it is executed. Consider bulk changes of many hundreds or thousands of objects, for instance. We need a mechanism by which we can freeze the object at the exact point in time.

@jeremystretch commented on GitHub (Sep 14, 2020): > query for the actual object inside the job I don't think we can make the assumption that the object has not changed between the point in time when the job is queued and the time when it is executed. Consider bulk changes of many hundreds or thousands of objects, for instance. We need a mechanism by which we can freeze the object at the exact point in time.
Author
Owner

@lampwins commented on GitHub (Sep 14, 2020):

Yeah good point, it also doesn't work for deleted objects.

@lampwins commented on GitHub (Sep 14, 2020): Yeah good point, it also doesn't work for deleted objects.
Author
Owner

@stale[bot] commented on GitHub (Oct 30, 2020):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Oct 30, 2020): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@stale[bot] commented on GitHub (Nov 14, 2020):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@stale[bot] commented on GitHub (Nov 14, 2020): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3527