Custom link to run a script right away #15515
-
I'm figuring out a way to provide a custom link to run a NetBox script. This is for prefix model, and the purpose of the script is to provide user some externally-retrieved extra information about the prefix. I see that I can create a custom script, and then create a custom link with the script URL (with the prefix/ID given as a URL parameter). But when clicking the custom link the user then gets the normal script run page: " Also the output after running the script is suboptimal, showing the technical data of running the script in addition to the "console" output of the script. What I would like to get is that the script runs right away when the link is clicked, and the user gets shown the resulting output, which is not NetBox data but something else, basically some nicely formatted read-only table output. How could a plugin be used to provide this functionality? To be clear, I don't want to integrate the output of the script right into the prefix page because retrieving the data is expensive (in terms of execution time and external resource usage), so I need the data to be retrieved and shown on a separate page only when clicking the custom link. Almost all the plugins I've browsed seem to implement their own data models and thus show the database contents, or they integrate in the object pages and show some data pane over there. I haven't found a "Hello, World!" page output plugin yet (*) 😃 So I'm kind of lost right in the start already. The Nagios plugin listed in https://github.com/netbox-community/netbox/wiki/Plugins comes closest yet: it retrieves and shows external data (not data from NetBox database), but it shows it within the device page, not in a separate URL/page. When thinking about the plugin approach, I guess it is something like this:
Do you have any pointers or helpful comments to proceed? I'm willing to publish the "Hello, World!" page plugin if this succeeds 🙂 (*) I did find this: https://github.com/cruse1977/netbox-plugin-helloworld, which exposes a NetBox API URL and returns JSON output. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Well, what do you know, I read the documentation once more and realized some hints that were not model-dependent, and managed to do this: So, I think I have something here... |
Beta Was this translation helpful? Give feedback.
-
There it is now, https://github.com/markkuleinio/netbox-hello-world-page Feel free to add this to the plugins wiki page if it looks useful for someone. |
Beta Was this translation helpful? Give feedback.
-
Now, maybe someone with more NetBox plugins experience can explain this: Since installing this plugin in my test instance the loading of NetBox frontpage has started taking 75 seconds, occasionally. What could cause this? The plugin does not load anything, and shouldn't execute when the frontpage is accessed. Setting |
Beta Was this translation helpful? Give feedback.
There it is now,
netbox_hello_world_page
plugin:https://github.com/markkuleinio/netbox-hello-world-page
Feel free to add this to the plugins wiki page if it looks useful for someone.