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.22k stars 2.47k forks source link

Custom script logs are missing hyperlinks #16149

Open hendrikbl opened 4 weeks ago

hendrikbl commented 4 weeks ago

Deployment Type

Self-hosted

NetBox Version

v4.0.2

Python Version

3.11

Steps to Reproduce

  1. Create a custom script with logs using self.log_info(some_object, message)
  2. Run the script to write the logs
  3. View the logs in the jobs log view

Expected Behavior

Prior to 4.0 the object passed to log_info was displayed with a hyperlink to quicly reach the details view.

Observed Behavior

Now we have a URL column instead wich we have to copy and paste into the browser or search for the name of the object.

hendrikbl commented 4 weeks ago

Having this functionality for script logs would also be nice. Currently the same logging functions are used in the run function as well as the test_ functions. But when called from inside the run function, the second parameter (which is the object) is never displayed in the logs on the front end. There is simply no column to display the value. I think in an effort to merge scripts and reports it would be nice to also get some consistency there.

Alef-Burzmali commented 3 weeks ago

More generally, it seems that the logging functions for scripts (syntax log_info(message, obj)) ignore the obj argument in NetBox 4.0, despite the documentation saying otherwise. Note also that the documentation is naming the argument object= where it should be obj= according to the code.

https://github.com/netbox-community/netbox/blob/44771d1221f617cc8175397bf75bd0c4c7797f9b/netbox/extras/scripts.py#L496-L508

The obj parameter is not referenced in the JSON that is stored in the DB. It is however prepended to the message in the system/console logs. You can also verify in the DB directly: select * from core_job order by id desc limit 1 \gx (to get the results of the last script execution). data["log"] has no reference to any object.

jeremystretch commented 3 weeks ago

@arthanson what is the status of this issue?