-
Notifications
You must be signed in to change notification settings - Fork 96
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
Add support for smart
command
#15
base: master
Are you sure you want to change the base?
Conversation
@Chronial anything I need to do to close out this MR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to review this and thx for the reminder :).
snapraid-runner.py
Outdated
@@ -150,6 +155,7 @@ def load_config(args): | |||
|
|||
config["smtp"]["ssl"] = (config["smtp"]["ssl"].lower() == "true") | |||
config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true") | |||
config["smart"]["enabled"] = (config["smart"]["enabled"].lower() == "true") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this save, or will this raise an exception if the smart
section is missing from the config? I don't remember ^^.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll test & confirm what happens if the config omits this section and design a method to handle if it raises an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed it does not throw an error with latest code on Windows & Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx 👍
snapraid-runner.py
Outdated
if config["smart"]["enabled"]: | ||
logging.info("Running SMART...") | ||
# Expand PATH to include /usr/sbin for running smartctl from cron | ||
os.environ["PATH"] += os.pathsep + "/usr/sbin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clearly not cross-platform :). Even on unix it makes strong assumptions about the user's setup. I assume you had problems with the binary not being found? Why don't you make the binary path a setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I definitely overlooked the fact that snapraid is cross-platform and wrote this for Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably remove this and just make sure the command is run in the correct environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I handled this with known paths in my latest commit. What do you think of the changes to make it cross-platform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It look very comprehensive, but I don't think this script should make any attempt to find the executable. That is just very complicated and the PATH system of the OSs is perfectly suitable to handle this job. I will have a look and do some changes to this PR.
snapraid-runner.py
Outdated
else: | ||
threads = [ | ||
tee_log(p.stdout, out, logging.OUTPUT), | ||
tee_log(p.stderr, [], logging.OUTERR)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which output belongs to which command is always clearly identifiable from the headers. Why does smart
need this logging trickery?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a new SMART logging level that is output in both "short" and "long" logging modes since it is highly likely that it is always desired to view the SMART output if you are sending emails on success. It does not output if set to only error notification emails since the log level is set one level higher than error logging. This section ensures the SMART "OUTPUT" logging is redirected into "SMART" logging while leaving all other logging as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok – that makes sense. Please add a comment about that to where you define that loglevel.
Also add an output_log_level
parameter to this function and use that instead of this if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment on line 175 to highlight the SMART logging level creation, but I'm not sure what you're looking for in the output_log_level
instead of this if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. I meant that the signature should be snapraid_command(command, args={}, ignore_errors=False, output_log_level=logging.OUTPUT)
and then use the parameter instead of guessing based on the name of the command.
Thanks for working on this! 🎉 |
smart
commandsmart
command
The formatting output in the email isn't the greatest, but it's enough to discern the result of the SMART command.