Restore ability for scripts to be able to log_success without generating a message #9753

Closed
opened 2025-12-29 21:22:05 +01:00 by adam · 4 comments
Owner

Originally created by @candlerb on GitHub (May 27, 2024).

Originally assigned to: @Julio-Oliveira-Encora on GitHub.

NetBox version

v4.0.3

Feature type

Change to existing functionality

Proposed functionality

Make log_success(None, None) and/or log_success("", None) increment the success counter without generating a log message

Use case

Reports in Netbox <= v3.7 were able to do this:

self.log_success(obj)

This would increment the success counter for the report without generating any message: e.g.

image

However, in Netbox 4.0, when upgrading a Report to a Script, you need to change it to:

self.log_success("", obj)
or
self.log_success(None, obj)
or
self.log_success(None, None)

All of these log a message: a dash in the first case, or the string "None" in the second and third. (The third log line has no URL).

Either way, if you have thousands of successful checks, this generates thousands of log lines to wade through.

I note from the documentation of v3.7 that omitting the message for log_success() in Reports was explicitly permitted, and defaulted to None:

* log(message)
* log_success(object, message=None)
* log_info(object, message)
* log_warning(object, message)
* log_failure(object, message)

Maybe also log_success() with no arguments should be allowed, since the object identity isn't actually being used if no message is being recorded. It would be equivalent to log_success(None, None)


Possibly relates to #8984, although I think that this feature request is orthogonal.

Database changes

None

External dependencies

None

Originally created by @candlerb on GitHub (May 27, 2024). Originally assigned to: @Julio-Oliveira-Encora on GitHub. ### NetBox version v4.0.3 ### Feature type Change to existing functionality ### Proposed functionality Make `log_success(None, None)` and/or `log_success("", None)` increment the success counter without generating a log message ### Use case Reports in Netbox <= v3.7 were able to do this: ``` self.log_success(obj) ``` This would increment the success counter for the report without generating any message: e.g. <img width="150" alt="image" src="https://github.com/netbox-community/netbox/assets/44789/c20371ce-7557-48d3-8c0c-d55790fd435e"> However, in Netbox 4.0, when upgrading a Report to a Script, you need to change it to: ``` self.log_success("", obj) or self.log_success(None, obj) or self.log_success(None, None) ``` All of these log a message: a dash in the first case, or the string "None" in the second and third. (The third log line has no URL). Either way, if you have thousands of successful checks, this generates thousands of log lines to wade through. I note from the documentation of v3.7 that omitting the message for `log_success()` in Reports was explicitly permitted, and defaulted to `None`: ``` * log(message) * log_success(object, message=None) * log_info(object, message) * log_warning(object, message) * log_failure(object, message) ``` Maybe also `log_success()` with no arguments should be allowed, since the object identity isn't actually being used if no message is being recorded. It would be equivalent to `log_success(None, None)` ----- Possibly relates to #8984, although I think that this feature request is orthogonal. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:22:05 +01:00
adam closed this issue 2025-12-29 21:22:06 +01:00
Author
Owner

@Julio-Oliveira-Encora commented on GitHub (May 30, 2024):

Could you please assign it to me?

@Julio-Oliveira-Encora commented on GitHub (May 30, 2024): Could you please assign it to me?
Author
Owner

@jeremystretch commented on GitHub (Jun 21, 2024):

@candlerb I'm a little unclear on the reproduction. Are you using a legacy report, or a custom script? Report methods use the signature

log_success(obj=None, message=None)

whereas Script methods use the signature

log_success(message, obj=None)
@jeremystretch commented on GitHub (Jun 21, 2024): @candlerb I'm a little unclear on the reproduction. Are you using a legacy report, or a custom script? Report methods use the signature ```python log_success(obj=None, message=None) ``` whereas Script methods use the signature ```python log_success(message, obj=None) ```
Author
Owner

@candlerb commented on GitHub (Jun 21, 2024):

A new custom script, using the Script signature you gave.

If I understand correctly, Scripts are now supposed to subsume the functionality originally in reports (and the fact you refer to reports as "legacy" seems to confirm this).

However, I was unable to invoke Script.log_success() in a way which was able to increment the "success" counter without logging a message, as reports are/were able to do.

As I wrote earlier, I tried:

self.log_success("", obj)
self.log_success(None, obj)
self.log_success(None, None)

but all of these log an empty message - so if you have 2,000 successes you get 2,000 log messages, making it very hard to wade through to the errors (and of course slowing things down).

@candlerb commented on GitHub (Jun 21, 2024): A new custom script, using the Script signature you gave. If I understand correctly, Scripts are now supposed to subsume the functionality originally in reports (and the fact you refer to reports as "legacy" seems to confirm this). However, I was unable to invoke Script.log_success() in a way which was able to increment the "success" counter without logging a message, as reports are/were able to do. As I wrote earlier, I tried: ``` self.log_success("", obj) self.log_success(None, obj) self.log_success(None, None) ``` but all of these log an empty message - so if you have 2,000 successes you get 2,000 log messages, making it very hard to wade through to the errors (and of course slowing things down).
Author
Owner

@jeremystretch commented on GitHub (Jun 21, 2024):

Ok, thanks. NetBox v4.0 retains backward compatibility for legacy Reports too so I just wasn't clear which form of the method we're looking at.

@jeremystretch commented on GitHub (Jun 21, 2024): Ok, thanks. NetBox v4.0 retains backward compatibility for legacy Reports too so I just wasn't clear which form of the method we're looking at.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9753