Custom scripts with linked Object var fields possible? #9702
-
Hi, This might be a bit out there but it would be realy realy nice if this is possible. Is it possible to link objectvar fields. Eg: First field would be: Second field select the VM's
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
see #9521 |
Beta Was this translation helpful? Give feedback.
-
I'm not a great web developer but part of the problem implementing this kind of thing is that the two events, building the page and transmitting it to your browser and selecting options from the rendered page, happen at different times on different computers entirely, so the program which generates the page for you in the Script can't incorporate knowledge of what you clicked on on a different computer seconds or minutes later. IIUC for Script it's building HTML form elements based on the variables you declare and pre-written jinja2 templates to make each kind of form element (checkbox, selection list, text field, etc.).
One way would be to put validation logic when the Script is being run and error out with a helpful message if there is a mismatch between VM and Tenant as in your example, that won't prevent people from entering in bogus data but it will prevent bogus data from making it into Netbox. It's good to do server-side validation anyway, as the web client doesn't really have to follow the rules anyway (some joker could go into web developer mode and submit the form with any crazy nonsense they want).
Another way you might be able to solve this problem is to find a way to include some custom locally written JavaScript in the page, then when a person selects an option in one form element, the JS program can be notified and may be able to operate on the second form element, assuming all the information it needs is in the page, or it can do API queries itself in JS and use that to rewrite the second form element options. I have no idea how any of this could be automated such that you could declare it in the Script and have the jinja templates build these JS hooks in the way you would need as it's going to be different for different data types and sites.
This approach seems complicated and unreliable, and I may be missing some simple way to make it easier, but at some point, you either can accept some limitations for the pre-made tools, because implementing absolutely everything is not possible, or build a custom plugin as the escape hatch for any workflow that is too complex and needs wholly custom pages and custom javascript to work.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: MalfuncEddie ***@***.***>
Sent: Monday, July 11, 2022 7:35 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Custom scripts with linked Object var fields possible? (Discussion #9702)
Hi,
This might be a bit out there but it would be realy realy nice if this is possible.
I only started netbox scripting a couple of days ago and reading through the documentation (https://docs.netbox.dev/en/stable/customization/custom-scripts/#objectvar) I see that you can filter with query_params.
Is it possible to link objectvar fields.
Eg:
A script that gets certain vm's of a tenant and do some scripting on it and send it to an 3rd party api.
First field would be:
Select the tenant
Second field select the VM's
--> it would be nice if the query_params would make it so that it only shows the vm's of the tenant selected in the first field.
class Meta:
name = "Generate report for tenant"
description = "Generate report for tenant"
tenant = ObjectVar(model=Tenant)
vms = MultiObjectVar(model=Contact,query_params=<see variable tenant> )
—
Reply to this email directly, view it on GitHub<#9702>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UMZ6NGDHI2BP37RLX5TVTQIKVANCNFSM53HLVUBA>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
see #9521