Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
candlerb opened this issue May 27, 2024 · 4 comments · Fixed by #16697
Closed

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

candlerb opened this issue May 27, 2024 · 4 comments · Fixed by #16697
Assignees
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@candlerb
Copy link
Contributor

candlerb commented May 27, 2024

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

@candlerb candlerb added status: needs triage This issue is awaiting triage by a maintainer type: feature Introduction of new functionality to the application labels May 27, 2024
@jeremystretch jeremystretch removed their assignment May 28, 2024
@jeremystretch jeremystretch added status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation complexity: low Requires minimal effort to implement and removed status: needs triage This issue is awaiting triage by a maintainer labels May 28, 2024
@Julio-Oliveira-Encora
Copy link
Contributor

Could you please assign it to me?

@arthanson arthanson added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels May 30, 2024
@jeremystretch
Copy link
Member

@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)

@candlerb
Copy link
Contributor Author

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).

@jeremystretch
Copy link
Member

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.

@candlerb candlerb changed the title Restore ability for reports to be able to log_success without generating a message Restore ability for scripts to be able to log_success without generating a message Jun 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
complexity: low Requires minimal effort to implement status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
4 participants