Add support for jinja2 custom filters for webhooks #6548

Closed
opened 2025-12-29 19:42:12 +01:00 by adam · 3 comments
Owner

Originally created by @tom0010 on GitHub (Jun 8, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.2.3

Feature type

Change to existing functionality

Proposed functionality

When using webhooks, I'd like to have the ability to add some custom jinja2 filters.
Ansible comes with some nice ones, such as to_nice_yaml etc. however, I'd like to have the ability to add filters where you see fit.

Maybe something like https://github.com/tbotnz/netpalm-admin would work, where you can just paste the filter into the GUI and it'll be uploaded to the netbox instance, failing that, we could also add a jinja2_filters folder somewhere, where the user could just add the filters there. Similarly to the scripts design in Netbox.

Use case

It would allow users to customise the payload better when using webhooks.

Database changes

Not sure.

External dependencies

Jinja2

Originally created by @tom0010 on GitHub (Jun 8, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.2.3 ### Feature type Change to existing functionality ### Proposed functionality When using webhooks, I'd like to have the ability to add some custom jinja2 filters. Ansible comes with some nice ones, such as `to_nice_yaml` etc. however, I'd like to have the ability to add filters where you see fit. Maybe something like https://github.com/tbotnz/netpalm-admin would work, where you can just paste the filter into the GUI and it'll be uploaded to the netbox instance, failing that, we could also add a `jinja2_filters` folder somewhere, where the user could just add the filters there. Similarly to the `scripts` design in Netbox. ### Use case It would allow users to customise the payload better when using webhooks. ### Database changes Not sure. ### External dependencies Jinja2
adam added the status: acceptedtype: feature labels 2025-12-29 19:42:12 +01:00
adam closed this issue 2025-12-29 19:42:12 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jun 8, 2022):

I think it makes sense to allow injecting custom jinja2 filters. I think the only implementation that would make sense for a feature is this is that we just add a configuration option similar to what we have for Custom Validation (see. Direct Class Reference).

Allowing you to have something like this in your configuration.py (the function can of course be included from wherever).

def to_lower(input):
    return input.lower()

JINJA2_FILTERS = [to_lower]

Would that be fine for your usecase @tom0010 ? Having a field to paste code is a little icky for a feature that will be used by few.

@kkthxbye-code commented on GitHub (Jun 8, 2022): I think it makes sense to allow injecting custom jinja2 filters. I think the only implementation that would make sense for a feature is this is that we just add a configuration option similar to what we have for Custom Validation (see. [Direct Class Reference](https://docs.netbox.dev/en/stable/customization/custom-validation/)). Allowing you to have something like this in your configuration.py (the function can of course be included from wherever). ``` def to_lower(input): return input.lower() JINJA2_FILTERS = [to_lower] ```` Would that be fine for your usecase @tom0010 ? Having a field to paste code is a little icky for a feature that will be used by few.
Author
Owner

@tom0010 commented on GitHub (Jun 8, 2022):

I think that would work.
Thanks @kkthxbye-code 🙂

Edit: also, would this allow to use these filters elsewhere, and not just in webhooks, maybe scripts too?

@tom0010 commented on GitHub (Jun 8, 2022): I think that would work. Thanks @kkthxbye-code 🙂 Edit: also, would this allow to use these filters elsewhere, and not just in webhooks, maybe scripts too?
Author
Owner

@kkthxbye-code commented on GitHub (Jun 10, 2022):

@tom0010 - It will be avaliable where jinja2 is used which is:

  • Custom Links (url and label)
  • Webhooks (url, headers, body)
  • Export templates
@kkthxbye-code commented on GitHub (Jun 10, 2022): @tom0010 - It will be avaliable where jinja2 is used which is: * Custom Links (url and label) * Webhooks (url, headers, body) * Export templates
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6548