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

Add support for smart command #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

k3vmcd
Copy link

@k3vmcd k3vmcd commented Sep 24, 2017

The formatting output in the email isn't the greatest, but it's enough to discern the result of the SMART command.

@k3vmcd
Copy link
Author

k3vmcd commented Oct 23, 2017

@Chronial anything I need to do to close out this MR?

Copy link
Owner

@Chronial Chronial left a 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 :).

@@ -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")
Copy link
Owner

@Chronial Chronial Oct 23, 2017

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

Copy link
Author

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.

Copy link
Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx 👍

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"
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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.

Copy link
Author

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?

Copy link
Owner

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.

else:
threads = [
tee_log(p.stdout, out, logging.OUTPUT),
tee_log(p.stderr, [], logging.OUTERR)]
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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.

Copy link
Author

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

Copy link
Owner

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.

@OJFord
Copy link

OJFord commented Feb 25, 2018

Thanks for working on this! 🎉

@Chronial
Copy link
Owner

@k3vmcd I simplified the implementation a bit. Does this still fulfill your requirements? Please see here how to fix your PATH issue on cron.

jbrekle added a commit to jbrekle/snapraid-runner that referenced this pull request Dec 12, 2019
@Chronial Chronial changed the title Chronial/snapraid-runner Issue #3: Add support for smart command Add support for smart command Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants