netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Public demo: https://demo.netbox.dev
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.23k stars 2.47k forks source link

Missing "Run Script" button from Custom Scripts #16153

Closed kollross closed 4 weeks ago

kollross commented 1 month ago

Deployment Type

Self-hosted

NetBox Version

v4.0.2

Python Version

3.10

Steps to Reproduce

  1. Click on Customizations -> Scripts
  2. Can view script in the list (has edit, and delete buttons)
  3. No "Run Script option"

This script was working yesterday, I upgraded to 4.0.2 today and now that script is missing the button. Other scripts still have the "Run Script" option.

Expected Behavior

"Run Script" button be present and clickable.

Observed Behavior

emptyness

arthanson commented 1 month ago

@kollross Thank you for opening a bug report. I was unable to reproduce the reported behavior on NetBox v4.0.2. "that script is missing the button." I don't know what that script is - the existing scripts I have on my installation still have the Run Script button. Can you please check what is different about the script then your other scripts, generally a run script button missing would indicate that there is an issue with the script code.

bitcollector1 commented 1 month ago

I believe I have the same issue.

Screenshot 2024-05-15 at 15 39 27

What is worse is there is no way to delete the script now Screenshot 2024-05-15 at 15 39 33

Screenshot 2024-05-15 at 15 39 38

arthanson commented 1 month ago

@bitcollector1 "What is worse is there is no way to delete the script now" please file a separate issue if you are running into this and can reproduce.

arthanson commented 1 month ago

Note: There is a PR #15441 that adds better script error reporting (to show errors in the script code) - I'm guessing (without a repo scenario) that the scripts without the run button has an error, that PR would make it easier to find.

bitcollector1 commented 4 weeks ago

I was able to delete my script that had issues by going into the shell and deleting the event rule that was causing the issue deleting the problematic script

>>> EventRule.objects.all()
<RestrictedQuerySet [<EventRule: IP Updated>]>

>>> EventRule.objects.all().delete()
(2, {'extras.EventRule_object_types': 1, 'extras.EventRule': 1})
>>> 
>>> EventRule.objects.all().delete()
(0, {})
bitcollector1 commented 4 weeks ago

I can see my script now, it was in fact related to an error in the code that was preventing it from loading correctly.

Thanks you @arthanson very much for helping me see and fix my issue. This can get very tricky, with all the dependencies and changes going on :)

  1. Made change to existing code but had a syntax error
  2. Script then broke, but gave no real warning.....other than disappearing from GUI (I was using curl so did not see this)
  3. I was not able to delete the script due to the fact it was tied to the event rule
  4. I then had to go into nbshell to delete the event rule --> could not do it from GUI
  5. then I was able to delete the problem script
  6. finally able to reupload the new working script that had no errors.
kollross commented 4 weeks ago

During the upgrade to 4.0.2 one of the required pip modules wasn't installed. But because I couldn't run the script from the GUI, there was no viable output to tell me it had a missing module. Deleting the script, and re-adding it produced a buttonless section of the script. Tailing the logs when deleting and re-adding the script also produced no errors. The only way I was able to troubleshoot to was to drop into /opt/netbox/venv/bin/python and running the script line by line to see where the erroring out.

Thank goodness for "https://github.com/netbox-community/netbox/discussions/12813" otherwise this sort of thing would also impossible to troubleshoot.