Closed candlerb closed 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.
Please keep this open. I have a number of scripts and I'm trying to build a new instance of NetBox. Some of these scripts haven't been looked at for a while and invariably contain errors against the latest version. The problem is, importing these scripts fails and I am unable to identify where the errors are.
I second the request to keep this open and find a solution. Debugging scripts is a real PITA.
@cpmills1975 @jhofmueller would either of you like to volunteer to work on this issue? It has been tagged as needs owner
. If no one volunteers, it will be closed with the assumption that it is not worthwhile for anyone to work on.
Quite frankly I fear I would be in over my head. I am pretty confident doing admin stuff with netbox, adding templates, using the API and so on but am quite unfamiliar with the internal workings. Can you point me somewhere to get started so I could estimate the amount of time needed and check back with my colleagues?
Closing as stale as there have been no volunteers.
Just saying this here: Looks like NetBox is logging the script errors after all, at least on 3.7.0:
2024-01-18 10:46:09,170 netbox.data_backends DEBUG: Failed to load script: Tunnel error: name 'Script' is not defined
Obviously this requires manual configuration of LOGGING
. Example of such configuration is in https://majornetwork.net/2022/09/configuring-logging-in-netbox/:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'normal': {
'format': '%(asctime)s %(name)s %(levelname)s: %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.WatchedFileHandler',
'filename': '/var/log/netbox/netbox.log',
'formatter': 'normal',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'INFO',
},
'netbox': {
'handlers': ['file'],
'level': 'INFO',
},
},
}
Note that in the example the file handler is logging DEBUG level (and up), but the loggers below that (django
and netbox
) are set to INFO, so to get the script errors in the log you need to set the netbox
logger to level DEBUG as well.
Logging this kind of error at DEBUG level is a bug in my opinion. I tried submitting a PR for that but it was rejected. So to avoid spamming the log with tons of debug level messages, I found that I can enable debug level only for netbox.data_backends
. My full logging configuration is below. I'm sending it to syslog, which is picked up by otel-collector and forwarded to my centralized log server.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'rfc3164': {
'format': '{name}: {message}',
'style': '{',
},
},
'handlers': {
'syslog': {
'class': 'logging.handlers.SysLogHandler',
'address': '/dev/log',
'level': 'DEBUG',
'formatter': 'rfc3164',
},
},
'loggers': {
'netbox': {
'handlers': ['syslog'],
'level': 'INFO',
},
'django': {
'handlers': ['syslog'],
'level': 'INFO',
},
'rq.worker': {
'handlers': ['syslog'],
'level': 'INFO',
},
'netbox.data_backends': {
'handlers': ['syslog'],
'level': 'DEBUG',
},
},
}
NetBox version
v3.5.2
Feature type
Change to existing functionality
Proposed functionality
If you upload a script but there's a problem in it, there's no information displayed beyond this:
Nothing is sent to Netbox logs either. I would like the actual exception to be displayed.
Use case
It's very hard to develop a script if you don't know what's wrong with it!
Using
runscript
from the command line doesn't help: it just returns the same as if you'd specified the wrong name for the class.Trying to run the script directly from the command line, it doesn't have the right environment set up:
Setting PYTHONPATH by itself is insufficient. In the end I used this recipe to run the script, by inserting the following lines at the top:
And finally I got the error I was looking for:
But this seems to be way too hard :-(
Database changes
None
External dependencies
None