-
Notifications
You must be signed in to change notification settings - Fork 97
Add support for smart
command - slightly different
#24
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -45,11 +45,13 @@ def tee_thread(): | |||||||
return t | ||||||||
|
||||||||
|
||||||||
def snapraid_command(command, args={}, *, allow_statuscodes=[]): | ||||||||
def snapraid_command(command, args={}, *, allow_statuscodes=[], log_output = False): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO
Suggested change
|
||||||||
""" | ||||||||
Run snapraid command | ||||||||
Raises subprocess.CalledProcessError if errorlevel != 0 | ||||||||
""" | ||||||||
stdout_level = logging.INFO if log_output else logging.OUTPUT | ||||||||
stderr_level = logging.ERROR if log_output else logging.OUTERR | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you change the loglevel of stderr here? |
||||||||
arguments = ["--conf", config["snapraid"]["config"]] | ||||||||
for (k, v) in args.items(): | ||||||||
arguments.extend(["--" + k, str(v)]) | ||||||||
|
@@ -61,8 +63,8 @@ def snapraid_command(command, args={}, *, allow_statuscodes=[]): | |||||||
) | ||||||||
out = [] | ||||||||
threads = [ | ||||||||
tee_log(p.stdout, out, logging.OUTPUT), | ||||||||
tee_log(p.stderr, [], logging.OUTERR)] | ||||||||
tee_log(p.stdout, out, stdout_level), | ||||||||
tee_log(p.stderr, [], stderr_level)] | ||||||||
for t in threads: | ||||||||
t.join() | ||||||||
ret = p.wait() | ||||||||
|
@@ -163,6 +165,7 @@ def load_config(args): | |||||||
config["scrub"]["enabled"] = (config["scrub"]["enabled"].lower() == "true") | ||||||||
config["email"]["short"] = (config["email"]["short"].lower() == "true") | ||||||||
config["snapraid"]["touch"] = (config["snapraid"]["touch"].lower() == "true") | ||||||||
config["snapraid"]["smart"] = (config["snapraid"]["smart"].lower() == "true") | ||||||||
|
||||||||
if args.scrub is not None: | ||||||||
config["scrub"]["enabled"] = args.scrub | ||||||||
|
@@ -257,6 +260,14 @@ def run(): | |||||||
logging.info("Running touch...") | ||||||||
snapraid_command("touch") | ||||||||
logging.info("*" * 60) | ||||||||
if config["snapraid"]["smart"]: | ||||||||
logging.info("Running smart...") | ||||||||
try: | ||||||||
snapraid_command("smart", log_output=True) | ||||||||
except subprocess.CalledProcessError as e: | ||||||||
logging.error(e) | ||||||||
finish(False) | ||||||||
logging.info("*" * 60) | ||||||||
|
||||||||
logging.info("Running diff...") | ||||||||
diff_out = snapraid_command("diff", allow_statuscodes=[2]) | ||||||||
|
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'd prefer for this to be false. Otherwise the script will fail per default if the user doesn't have smartctrl. Also a note
Make sure smartctl is in your PATH.
in the comment would be helpful.