Increase log level for faulty scripts #11462

Open
opened 2025-12-29 21:45:34 +01:00 by adam · 5 comments
Owner

Originally created by @llamafilm on GitHub (Aug 8, 2025).

NetBox version

v4.3.5

Feature type

Change to existing functionality

Proposed functionality

When a custom script has a missing import or some other syntax error, Netbox logs the error as DEBUG level. I think this would be more appropriate at ERROR level instead. For example, messages like this:

netbox.data_backends[4876]: Failed to load script: my_script error: No module named 'nonexistent_module'
netbox.data_backends[4878]: Failed to load script: my_script error: '(' was never closed (, line 9)

Use case

I send all Netbox logs to a central log server, usually filtered to INFO level and above, so these messages are missing, which makes it hard to troubleshoot bad scripts. As a workaround, I can set netbox.data_backends to DEBUG level, but this shouldn't be necessary.

Database changes

No response

External dependencies

No response

Originally created by @llamafilm on GitHub (Aug 8, 2025). ### NetBox version v4.3.5 ### Feature type Change to existing functionality ### Proposed functionality When a custom script has a missing import or some other syntax error, Netbox logs the error as DEBUG level. I think this would be more appropriate at ERROR level instead. For example, messages like this: > netbox.data_backends[4876]: Failed to load script: my_script error: No module named 'nonexistent_module' > netbox.data_backends[4878]: Failed to load script: my_script error: '(' was never closed (<string>, line 9) ### Use case I send all Netbox logs to a central log server, usually filtered to INFO level and above, so these messages are missing, which makes it hard to troubleshoot bad scripts. As a workaround, I can set `netbox.data_backends` to DEBUG level, but this shouldn't be necessary. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: blockednetboxcomplexity: low labels 2025-12-29 21:45:34 +01:00
Author
Owner

@llamafilm commented on GitHub (Aug 8, 2025):

This is a one line change, I can volunteer to do it.

@llamafilm commented on GitHub (Aug 8, 2025): This is a one line change, I can volunteer to do it.
Author
Owner

@jeremystretch commented on GitHub (Aug 14, 2025):

Let's hold off on this for the time being. A new job logging functionality is being introduced in NetBox v4.4 under #19816, which might address this. And if it doesn't, will at least inform the change to be made.

@jeremystretch commented on GitHub (Aug 14, 2025): Let's hold off on this for the time being. A new job logging functionality is being introduced in NetBox v4.4 under #19816, which might address this. And if it doesn't, will at least inform the change to be made.
Author
Owner

@llamafilm commented on GitHub (Aug 23, 2025):

I've started testing 4.4.0 now and I don't see any relevant changes for this particular issue. The two examples I gave above (bad import, or syntax error) don't log anything to the new netbox.jobs.ScriptJob logger. The script name disappears from the UI so you can't click on it, and there's no indication of what the problem might be, unless you enable DEBUG logging for netbox.data_backends.

Image
@llamafilm commented on GitHub (Aug 23, 2025): I've started testing 4.4.0 now and I don't see any relevant changes for this particular issue. The two examples I gave above (bad import, or syntax error) don't log anything to the new `netbox.jobs.ScriptJob` logger. The script name disappears from the UI so you can't click on it, and there's no indication of what the problem might be, unless you enable DEBUG logging for `netbox.data_backends`. <img width="967" height="146" alt="Image" src="https://github.com/user-attachments/assets/4bcba33b-aa1e-4fca-b2ba-7c2d8269b964" />
Author
Owner

@llamafilm commented on GitHub (Sep 16, 2025):

Can you assign this to me?

@llamafilm commented on GitHub (Sep 16, 2025): Can you assign this to me?
Author
Owner

@aj2s commented on GitHub (Oct 6, 2025):

Ya this would be great. We found some snippet online to surface it the error, but it requires updating the script temporarily. Ideally it would just appear in job log right away

The snippet that we put at top when debugging these errors.

import django, os, sys
sys.path.append('/opt/netbox/netbox')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'netbox.settings')
django.setup()
@aj2s commented on GitHub (Oct 6, 2025): Ya this would be great. We found some snippet online to surface it the error, but it requires updating the script temporarily. Ideally it would just appear in job log right away The snippet that we put at top when debugging these errors. ```python import django, os, sys sys.path.append('/opt/netbox/netbox') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'netbox.settings') django.setup() ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11462