diff --git a/README.md b/README.md index e0495d6..fbbc92f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,15 @@ It supports Windows, Linux and macOS and runs on both python2 and python3. * Can create a size-limited rotated logfile. * Can send notification emails after each run or only for failures. * Can run `scrub` after `sync` +* Can run `smart`. For this to work, you need [smartmontools](https://www.smartmontools.org/wiki/Download). + Most Linux distributions will have it installed installed by default. + * Windows users may install using the packaged .exe installer found at this link or + use [Chocolatey](https://chocolatey.org/) (i.e., `choco install smartmontools`). + * Mac OS users may install using the packaged .dmg installer found at this link or + use [Homebrew](https://brew.sh/) (i.e., `brew install smartmontools`). + * Linux users may check for smartmontools using `smartctl -V`, if not installed use + your distribution's package manager to install `smartmontools` + (e.g., `apt-get install smartmontools`, `yum install smartmontools`, etc.) ## Changelog ### v0.4 (17 Aug 2019) diff --git a/snapraid-runner.conf.example b/snapraid-runner.conf.example index ed64810..32a7bc4 100644 --- a/snapraid-runner.conf.example +++ b/snapraid-runner.conf.example @@ -7,6 +7,8 @@ config = snapraid.conf deletethreshold = 40 ; if you want touch to be ran each time touch = false +; prints a SMART report of all the disks of the array. +smart = true [logging] ; logfile to write to, leave empty to disable diff --git a/snapraid-runner.py b/snapraid-runner.py index 71d87c4..44b013b 100644 --- a/snapraid-runner.py +++ b/snapraid-runner.py @@ -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): """ 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 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])