Netbox: Custom Link to Run a Custom Script that Specifies the Object to Pass as a Paramter

This is a short and simple post to describe how in netbox you can create a custom button that invokes a netbox custom script, with parameters pre-populated.

In the example I use, the FindOwners button below is found only in the device page. Clicking it navigates to a particular script with the device in question a parameter in the script. The light green button to the right is similar and links to an external webpage with the device name inserted into the URL.

This post assumes the script is in place. In this case script FindOwners takes a single piece of data which is the device’s name. This is simply done by inserting the parameter in a jinga2 style as below. Clearly other parameters could be used like object.name or in an example I saw elsewhere the co-ordinates of the device’s location so that a map can show where to find a DC.

So the key point here is that custom links do not do anything other than allow a hyperlink to be created on the fly which include parameters referencing the object in the page the button appears in (if in a rack page, refers to the rack…).

What happens once the URL is called is dealt with elsewhere. Note that you can’t run a custom script from a hyperlink (whether from a custom link or other). the closest you can get is to pre-populate the form so the user has only to click the run button. However, parameters passed could be complex or initially not visible to the user (e.g. ID) and thus making the script easy to use.

Leave a comment

Create a website or blog at WordPress.com

Up ↑

Design a site like this with WordPress.com
Get started