Netbox JSON Conditions for Visibility of Custom Fields and Custom Links #9067

Closed
opened 2025-12-29 20:45:02 +01:00 by adam · 1 comment
Owner

Originally created by @cmcknz77 on GitHub (Jan 9, 2024).

NetBox version

v3.7.0

Feature type

Change to existing functionality

Proposed functionality

Currently Custom Fields have their visibility on a page controlled by the UI Visible model value which has 3 options:
Always, Hidden and "If Set".
Custom Links have their visibility controlled by the Enabled binary button.

I'd like to propose adding a Visibility Condition field to both of those models that takes input in the same form as the Netbox JSON Conditions https://docs.netbox.dev/en/stable/reference/conditions/ schema.

That way, if a Custom Link is set to Enabled and the condition in the Condition field doesn't evaluate to "True", the Custom Link doesn't show and if it evaluates to True it does.
If my example Custom Link points to the device page on my arbitrary monitoring platform (prtg in this case), I could have a Custom Link that points to

https://myprtg.virtual-server.org/device.htm?id={{ object.cf.prtg_id }}&tabid=1

only display if the associated custom field on that object has a value. That custom field exists on the device model but would not be populated on a device that we don't need to monitor. So it'd be viewable/clickable on a device with a non-null prtg_id field but not visible on, say, a patch panel or ODF (where that prtg_id field would probably be null). Given the link value of our custom Link is only going to point to a valid URL if the field it references has a value for the vast majority of the occasions on which this custom link is displayed currently, it's invalid (because the field upon which it relies is only filled in for a subset of the devices in the device list).

On a Custom Field the "If Set" option could change to "If condition is met", and we'd be able to recreate the Visible "If Set" functionality by setting the condition value to something like:

       {
               "attr": "custom_fields.prtg_id"
               "negate": true,
               "value": null
        }

But we'd also be able to only display a custom Field if other conditions were met. Say, for example you had a Base_MAC_Address custom field, you would be able to set the conditions so that that field becomes visible only for devices where such a field is relevant:

{
    "and": [
               {
               "attr": "role.name"
               "value": ["Router","Firewall","Gateway","Switch","AccessPoint"],
               "op": "in"
        }
   ]
}

So, Base_MAC_Address might show up on a Router, Firewall, Gateway, Switch or Access-Point but won't show up on an Antenna or a Patch Panel or a Power Panel.
If I have fields for GPS Lat & Long, elevation, and azimuth I could have those fields show up on the GUI for devices with the PtP or PtMP Radio device roles but not where they're irrelevant like on a Firewall, Media Converter or a console server without a network interface.

Use case

So, Base_MAC_Address might show up on a Router, Firewall, Gateway, Switch or AccessPoint but won't show up on an Antenna or a Patch Panel or a Power Panel.
If I have fields for GPS Lat & Long, elevation, and azimuth I could have those fields show up on the GUI for devices with the PtP or PtMP Radio device roles but not where they're irrelevant like on a Firewall, Media Converter or a console server without a network interface.

Database changes

I don't know what database changes would be required to support this functionality - perhaps a field on the Custom Link and Custom Field models to store the Visibility Conditions?

External dependencies

No response

Originally created by @cmcknz77 on GitHub (Jan 9, 2024). ### NetBox version v3.7.0 ### Feature type Change to existing functionality ### Proposed functionality Currently Custom Fields have their visibility on a page controlled by the UI Visible model value which has 3 options: Always, Hidden and "If Set". Custom Links have their visibility controlled by the Enabled binary button. I'd like to propose adding a Visibility Condition field to both of those models that takes input in the same form as the Netbox JSON Conditions https://docs.netbox.dev/en/stable/reference/conditions/ schema. That way, if a Custom Link is set to Enabled and the condition in the Condition field doesn't evaluate to "True", the Custom Link doesn't show and if it evaluates to True it does. If my example Custom Link points to the device page on my arbitrary monitoring platform (prtg in this case), I could have a Custom Link that points to > https://myprtg.virtual-server.org/device.htm?id={{ **object.cf.prtg_id** }}&tabid=1 only display if the associated custom field on that object has a value. That custom field exists on the device model but would not be populated on a device that we don't need to monitor. So it'd be viewable/clickable on a device with a non-null prtg_id field but not visible on, say, a patch panel or ODF (where that prtg_id field would probably be null). Given the link value of our custom Link is only going to point to a valid URL if the field it references has a value for the vast majority of the occasions on which this custom link is displayed currently, it's invalid (because the field upon which it relies is only filled in for a subset of the devices in the device list). On a Custom Field the "If Set" option could change to "If condition is met", and we'd be able to recreate the Visible "If Set" functionality by setting the condition value to something like: ``` { "attr": "custom_fields.prtg_id" "negate": true, "value": null } ``` But we'd also be able to only display a custom Field if other conditions were met. Say, for example you had a Base_MAC_Address custom field, you would be able to set the conditions so that that field becomes visible only for devices where such a field is relevant: ``` { "and": [ { "attr": "role.name" "value": ["Router","Firewall","Gateway","Switch","AccessPoint"], "op": "in" } ] } ``` So, **Base_MAC_Address** might show up on a Router, Firewall, Gateway, Switch or Access-Point but won't show up on an Antenna or a Patch Panel or a Power Panel. If I have fields for **GPS Lat & Long**, **elevation**, and **azimuth** I could have those fields show up on the GUI for devices with the **PtP** or **PtMP Radio** device roles but not where they're irrelevant like on a Firewall, Media Converter or a console server without a network interface. ### Use case So, **Base_MAC_Address** might show up on a Router, Firewall, Gateway, Switch or AccessPoint but won't show up on an Antenna or a Patch Panel or a Power Panel. If I have fields for **GPS Lat & Long**, **elevation**, and **azimuth** I could have those fields show up on the GUI for devices with the **PtP** or **PtMP Radio** device roles but not where they're irrelevant like on a Firewall, Media Converter or a console server without a network interface. ### Database changes I don't know what database changes would be required to support this functionality - perhaps a field on the Custom Link and Custom Field models to store the Visibility Conditions? ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:45:02 +01:00
adam closed this issue 2025-12-29 20:45:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 9, 2024):

I'm sorry, but similar functionality has already been proposed and rejected in various discussions. This is simply exceeds the intended purpose of custom fields. For use cases where the current implementation does not suffice, you'll need to create a custom plugin to extend NetBox's data model.

@jeremystretch commented on GitHub (Jan 9, 2024): I'm sorry, but similar functionality has already been proposed and rejected in various discussions. This is simply exceeds the intended purpose of custom fields. For use cases where the current implementation does not suffice, you'll need to [create a custom plugin](https://docs.netbox.dev/en/stable/development/) to extend NetBox's data model.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9067