Add support for Webhooks when accessing objects via the ORM #3927

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

Originally created by @dgarros on GitHub (Jul 30, 2020).

Environment

  • Python version: 3.7.7
  • NetBox version: 2.8.8

Proposed Functionality

Support a solution to be able to generate Webhooks when objects are changed via the ORM (Create/update/delete). Either automatically or manually.
As I understand, currently webhooks are managed in the class ObjectChangeMiddleware that is only executed in the context of a HTTP request.

Use Case

Support Webhooks for all changes done within scripts & plugins executed asynchronously in a worker. (#2006)

Database Changes

No change to the database

External Dependencies

I don't think so

Originally created by @dgarros on GitHub (Jul 30, 2020). ### Environment * Python version: 3.7.7 * NetBox version: 2.8.8 ### Proposed Functionality Support a solution to be able to generate Webhooks when objects are changed via the ORM (Create/update/delete). Either automatically or manually. As I understand, currently webhooks are managed in the class ObjectChangeMiddleware that is only executed in the context of a HTTP request. ### Use Case Support Webhooks for all changes done within scripts & plugins executed asynchronously in a worker. (#2006) ### Database Changes No change to the database ### External Dependencies I don't think so
adam added the type: featurestatus: needs ownerpending closure labels 2025-12-29 18:32:07 +01:00
adam closed this issue 2025-12-29 18:32:07 +01:00
Author
Owner

@cpmills1975 commented on GitHub (Aug 4, 2020):

Yes please! I am working on a script that imports devices and connections and rely heavily on webhooks to populate monitoring and management systems from NetBox. I didn't realise webhooks wouldn't fire and I will need to manage this via documentation and training initially.

@cpmills1975 commented on GitHub (Aug 4, 2020): Yes please! I am working on a script that imports devices and connections and rely heavily on webhooks to populate monitoring and management systems from NetBox. I didn't realise webhooks wouldn't fire and I will need to manage this via documentation and training initially.
Author
Owner

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

We discussed this in the maintainers' meeting today. I don't think it's feasible to support in a fully automated fashion, however @lampwins has the excellent idea of introducing a context manager for emulating a web request. This would allow a user to do something like the following (this is pseduo-code):

jstretch = User.objects.get(username='jstretch')
with WebRequestContext(user=jstretch):
    site = Site.objects.get(pk=1)
    site.name = 'Foo'
    site.save()

This would essentially be an alternative to the change_logging context manager used by middleware, with some adjustments to compensate for the absence of an actual HTTP request. More investigation is needed but this seems like a reasonable approach.

@jeremystretch commented on GitHub (Sep 15, 2020): We discussed this in the maintainers' meeting today. I don't think it's feasible to support in a fully automated fashion, however @lampwins has the excellent idea of introducing a context manager for emulating a web request. This would allow a user to do something like the following (this is pseduo-code): ```python jstretch = User.objects.get(username='jstretch') with WebRequestContext(user=jstretch): site = Site.objects.get(pk=1) site.name = 'Foo' site.save() ``` This would essentially be an alternative to the [`change_logging` context manager](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/context_managers.py#L10) used by middleware, with some adjustments to compensate for the absence of an actual HTTP request. More investigation is needed but this seems like a reasonable approach.
Author
Owner

@candlerb commented on GitHub (Sep 17, 2020):

Another option would be to use database triggers and stored procedures. Netbox is welded to Postgres so I would have no issue with using Postgres-specific functionality.

Hooks would then work even for direct SQL manipulation of the database.

@candlerb commented on GitHub (Sep 17, 2020): Another option would be to use database triggers and stored procedures. Netbox is welded to Postgres so I would have no issue with using Postgres-specific functionality. Hooks would then work even for direct SQL manipulation of the database.
Author
Owner

@dBitech commented on GitHub (Sep 17, 2020):

Can be quite easily with triggers notify.

See the following as example

https://gist.github.com/colophonemes/9701b906c5be572a40a84b08f4d2fa4e

On Thu., Sep. 17, 2020, 07:11 Brian Candler, notifications@github.com
wrote:

Another option would be to use database triggers and stored procedures.
Netbox is welded to Postgres so I would have no issue with using
Postgres-specific functionality.

Hooks would then work even for direct SQL manipulation of the database.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/netbox-community/netbox/issues/4932#issuecomment-694261940,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACOUKTRM2SX5R2IXNUIN4K3SGIKDPANCNFSM4POFFAEA
.

@dBitech commented on GitHub (Sep 17, 2020): Can be quite easily with triggers notify. See the following as example https://gist.github.com/colophonemes/9701b906c5be572a40a84b08f4d2fa4e On Thu., Sep. 17, 2020, 07:11 Brian Candler, <notifications@github.com> wrote: > Another option would be to use database triggers and stored procedures. > Netbox is welded to Postgres so I would have no issue with using > Postgres-specific functionality. > > Hooks would then work even for direct SQL manipulation of the database. > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/netbox-community/netbox/issues/4932#issuecomment-694261940>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ACOUKTRM2SX5R2IXNUIN4K3SGIKDPANCNFSM4POFFAEA> > . >
Author
Owner

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

Database triggers aren't something we can reasonably support for several reasons. Any implementation of this feature needs to be done in Python.

@jeremystretch commented on GitHub (Sep 17, 2020): Database triggers aren't something we can reasonably support for several reasons. Any implementation of this feature needs to be done in Python.
Author
Owner

@github-actions[bot] commented on GitHub (Jul 21, 2021):

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.

@github-actions[bot] commented on GitHub (Jul 21, 2021): 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

@github-actions[bot] commented on GitHub (Aug 20, 2021):

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.

@github-actions[bot] commented on GitHub (Aug 20, 2021): 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#3927