Replies: 3 comments
-
Example of current analysis return for Script validation >>> for module in ScriptModule.objects.all():
... print(f'\nModule: {module.name} (File: {module.file_path})')
... try:
... # First try to load the actual module
... module_obj = module.get_module()
... print('✅ Module loaded successfully')
...
... # Then try to load the scripts
... scripts = module.module_scripts
... if scripts:
... print('Scripts found:')
... for name, script_class in scripts.items():
... print(f' - {name}')
... else:
... print('⚠️ No scripts found in module')
...
... except ImportError as e:
... print(f'❌ Module import error: {str(e)}')
... print(' This usually means the module file is missing or has incorrect imports')
... except SyntaxError as e:
... print(f'❌ Syntax error in module: {str(e)}')
... print(' Check the module file for Python syntax errors')
... except AttributeError as e:
... print(f'❌ Attribute error: {str(e)}')
... print(' This might mean a script class is missing required attributes')
... except Exception as e:
... print(f'❌ Error loading module: {type(e).__name__}: {str(e)}')
...
Module: esn_ip_reservation.py (File: esn_ip_reservation.py)
✅ Module loaded successfully
Scripts found:
- AllocateSubnet
Module: esn_ip_reservation2.py (File: esn_ip_reservation2.py)
❌ Error loading module: FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/esn_ip_reservation2.py'
Module: esn_subnet_reservation.py (File: esn_subnet_reservation.py)
✅ Module loaded successfully
Scripts found:
- AllocateSubnet
Module: plugin-netbox-contract.py (File: plugin-netbox-contract.py)
❌ Module import error: cannot import name 'AccountingDimension' from 'netbox_contract.models' (/opt/netbox/netbox/netbox-contract/netbox_contract/models.py)
This usually means the module file is missing or has incorrect imports
Module: remove_disabled_tunnel.py (File: remove_disabled_tunnel.py)
❌ Error loading module: FileNotFoundError: [Errno 2] No such file or directory: '/opt/netbox/netbox/scripts/remove_disabled_tunnel.py'
``` |
Beta Was this translation helpful? Give feedback.
0 replies
-
I want that. I have wasted so much time with trial and error. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'd also like to see that implemented. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Feature Request: Script Validation Command
Problem Statement
When developing custom scripts in NetBox, there are two common issues that are only discovered at runtime:
BaseScript Property Override Issues
Script Loading Failures
Current Detection Method
Currently, users need to run code in nbshell to detect these issues:
Proposed Solution
Add a
validate_scripts
management command focused on these two issues:This would provide:
Example output:
Would this be helpful to add to NetBox core?
Beta Was this translation helpful? Give feedback.
All reactions