-
H! I want to create my Custom Links but ran into difficulty. I cannot find information on how the objects are correctly named in the Netbox. For example, my version does not work: Can you please tell me, did I enter the name of the object incorrectly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Firstly, the selected device is supplied as "obj", not "device". see: https://netbox.readthedocs.io/en/stable/additional-features/custom-links/#context-data For attributes of devices, you need to look at the models in the source code. For devices, the models are split over several files here. You can also explore the models interactively in the netbox shell. Device does not have an attribute called "interface", but it does have one called "interfaces" - because a device can have more than one interface. Therefore you need to iterate over the interfaces to find the one that you want. The same applies for IP addresses on an interface - each interface can have multiple IP addresses. Here is a working example, which iterates over interfaces to find the one with "Management Only" flag set. You can modify it to match on the name instead if you like (by changing By making the link text conditional, the button is hidden unless the device has exactly one interface with Management Only set, and that interface has exactly one IP address. Link text:
Link URL:
|
Beta Was this translation helpful? Give feedback.
Firstly, the selected device is supplied as "obj", not "device". see: https://netbox.readthedocs.io/en/stable/additional-features/custom-links/#context-data
For attributes of devices, you need to look at the models in the source code. For devices, the models are split over several files here. You can also explore the models interactively in the netbox shell.
Device does not have an attribute called "interface", but it does have one called "interfaces" - because a device can have more than one interface. Therefore you need to iterate over the interfaces to find the one that you want. The same applies for IP addresses on an interface - each interface can have multiple IP addresses.
Here is …