Allow referencing custom field values in custom link templates. #2854

Closed
opened 2025-12-29 18:22:49 +01:00 by adam · 2 comments
Owner

Originally created by @fknorn on GitHub (Sep 5, 2019).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.2

Proposed Functionality

Allow referencing of custom fields in custom links. Right now, it seems I cannot reference for instance obj.custom_fields.prtg_id in a custom link template.

Use Case

I have an external monitoring tool where devices have their own unique ID. I added a custom field for storing this ID, and I now would like to create deeplink to the device in the monitoring tool using that custom field.

Database Changes

Unsure, but I believe none, since the custom field functionality is already implemented.

External Dependencies

None.

Current result if attempting this

I am using this as Text in the custom link:

https://monitoring.example.com/device.htm?id={{ obj.custom_fields.prtg_id }}&tabid=1

but upon redering the device page, I get an exception

<class 'jinja2.exceptions.UndefinedError'>

'dcim.models.Device object' has no attribute 'custom_fields'

However, looking at the corresponding page with the API viewer that field is there:

HTTP 200 OK
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2,
[ -- snip -- ]
    "comments": "",
    "local_context_data": null,
    "tags": [],
    "custom_fields": {
        "prtg_id": 13951
    },
    "config_context": {},
[ -- snip -- ]
}
Originally created by @fknorn on GitHub (Sep 5, 2019). <!-- NOTE: 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.8 * NetBox version: 2.6.2 ### Proposed Functionality Allow referencing of custom fields in custom links. Right now, it seems I cannot reference for instance `obj.custom_fields.prtg_id` in a custom link template. ### Use Case I have an external monitoring tool where devices have their own unique ID. I added a custom field for storing this ID, and I now would like to create deeplink to the device in the monitoring tool using that custom field. ### Database Changes Unsure, but I believe none, since the custom field functionality is already implemented. ### External Dependencies None. ### Current result if attempting this I am using this as Text in the custom link: `https://monitoring.example.com/device.htm?id={{ obj.custom_fields.prtg_id }}&tabid=1` but upon redering the device page, I get an exception ``` <class 'jinja2.exceptions.UndefinedError'> 'dcim.models.Device object' has no attribute 'custom_fields' ``` However, looking at the corresponding page with the API viewer that field is there: ``` HTTP 200 OK Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "id": 2, [ -- snip -- ] "comments": "", "local_context_data": null, "tags": [], "custom_fields": { "prtg_id": 13951 }, "config_context": {}, [ -- snip -- ] } ```
adam closed this issue 2025-12-29 18:22:49 +01:00
Author
Owner

@rmrf-run commented on GitHub (Sep 5, 2019):

have you tried https://monitoring.example.com/device.htm?id={{obj.cf['prtg_id']}}&tabid=1? that is how my custom links are working with my monitoring tool

@rmrf-run commented on GitHub (Sep 5, 2019): have you tried `https://monitoring.example.com/device.htm?id={{obj.cf['prtg_id']}}&tabid=1`? that is how my custom links are working with my monitoring tool
Author
Owner

@jeremystretch commented on GitHub (Sep 5, 2019):

As @rmrf-run points out, custom fields are accessible under the cf property.

@jeremystretch commented on GitHub (Sep 5, 2019): As @rmrf-run points out, custom fields are accessible under the `cf` property.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2854