Package: netbox-script-manager
NetBox Script ManagerImproved custom script support for netbox. Netbox version 3.5 removed several features related to custom scripts. This plugin attempts to undo these changes and add other improvements to scripts in netbox.The plugin can be used in addition to the built-in script support and does not disable any netbox features.FeaturesScripts can be stored in nested modules.Scripts can rely on non-script module files.Scripts are loaded from a file-system folder.It's possible to sync scripts by pulling any git repo located in theSCRIPT_ROOTName, group, description, task queues, comments and tags are editable in the UI.Task queue is selectable in the UI.Exceptions caused by errors in script files are displayed in the UI.Log messages are saved and displayed when the script is running allowing live output for long running scripts.It's possible to filter log lines by message and/or log level.Changelog entries are listed in a tab when viewing a finished script execution.It's possible to save script artifacts during the execution of a script. These artifacts will show up as downloadable files.It's possible to re-run scripts.What is not supportedReportsDataSource/DataFileload_jsonandload_yamlconvenience methodsscript_order- the ordering of scripts is instead based ongroupandweightCompatibilityNetBox VersionPlugin Version3.50.1.0InstallingAdd the plugin tolocal_requirements.txtorplugin_requirements.txt(netbox-docker):netbox-script-managerEnable the plugin in/opt/netbox/netbox/netbox/configuration.py,
or if you use netbox-docker, your/configuration/plugins.pyfile:PLUGINS=['netbox_script_manager']PLUGINS_CONFIG={"netbox_script_manager":{"SCRIPT_ROOT":"/path/to/script/folder/","DEFAULT_QUEUE":"high"},}ConfigurationThe following options are required:SCRIPT_ROOT: Path to the script folder containing the customscripts module.The following options are optional:DEFAULT_QUEUE: Specifies what queue scripts are run in by default. Defaults to thedefaultqueue.Migrating scriptsThe most important change is to change the import and name of the baseScriptclass.Netbox Script:fromextras.scriptsimportScriptclassMyCustomScript(Script):...Netbox Script Manager Script:fromnetbox_script_manager.scriptsimportCustomScriptclassMyCustomScript(CustomScript):...It is strongly recommended to do relative imports in your scripts, when using a nested structure or utility code.from.utilimportmy_utility_methodfrom..subfolderimportmyCustomScriptThe alternative is to do an absolute import:fromcustomscripts.nested_folder.utilimportmy_utility_methodfromcustomscripts.subfolderimportmyCustomScriptPlease see theScript foldersection for instructions regarding folder structure.Script folderThe loading of scripts is a little different with netbox-script-manager. TheSCRIPT_ROOTplugin setting must be set to define the path of the custom scripts, however the scripts must be located in a folder namedcustomscriptsin this path.A folder structure like this is required (SCRIPT_ROOTpointing to thenetboxscriptsfolder):├──netboxscripts# SCRIPT_ROOT│├──customscripts# Scripts will be discovered in this module, must be present││├──__init__.py
││├──nestedmodule
││├──root_script.py
││└──util
│└──__init__.pyThe reason for requiring this layout with acustomscriptsfolder is to avoid name collisions when dynamically loading scripts. It also makes it easier to clear the internal python module cache which is needed for reloading scripts.Loading scripts is done either through the UI by pressing theLoad Scriptsbutton on the script view, or by calling the API endpoint/api/plugins/script-manager/script-instances/load/. Both of these require that the user has theCan Addaction for theScript Instanceobject permission.Git Sync:grey_exclamation: git must be installed on the system.:grey_exclamation: The netbox user must have thesyncadditional action for theScript Instanceobject permission.:warning: git recurses parent directories until finding a git directory. Make sure theSCRIPT_ROOTis a git directory.Netbox Script Manager has basic support for pulling down changes for git repositories. The Sync button is located on the script list and simply callsgit pullon in theSCRIPT_ROOT/customscriptsfolder. If the git reposity requires authentication, it's recommended to setup SSH auth for the repo and provide the key in the users$HOME/.sshfolder.If more advanced syncing is required, its recommended to handle this outside of netbox or alternatively use a custom script to do the sync.ScreenshotsTODO