From 4d9ab2215bed296d54803055cf2d9164e2c4995f Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Mon, 8 Apr 2019 18:57:38 -0700 Subject: [PATCH] Ensure SMART values are shown for some disks * smartctl can return non-zero if there are errors in the SMART logs --- .bin/Scripts/functions/hw_diags.py | 2 +- .bin/Scripts/functions/json.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bin/Scripts/functions/hw_diags.py b/.bin/Scripts/functions/hw_diags.py index f5235111..4b018447 100644 --- a/.bin/Scripts/functions/hw_diags.py +++ b/.bin/Scripts/functions/hw_diags.py @@ -350,7 +350,7 @@ class DiskObj(): def get_smart_details(self): """Get data from smartctl.""" cmd = ['sudo', 'smartctl', '--all', '--json', self.path] - self.smartctl = get_json_from_command(cmd) + self.smartctl = get_json_from_command(cmd, check=False) # Check for attributes if KEY_NVME in self.smartctl: diff --git a/.bin/Scripts/functions/json.py b/.bin/Scripts/functions/json.py index b4527c0d..49481903 100644 --- a/.bin/Scripts/functions/json.py +++ b/.bin/Scripts/functions/json.py @@ -4,7 +4,7 @@ import json from functions.common import * -def get_json_from_command(cmd, ignore_errors=True): +def get_json_from_command(cmd, check=True, ignore_errors=True): """Capture JSON content from cmd output, returns dict. If the data can't be decoded then either an exception is raised @@ -17,7 +17,7 @@ def get_json_from_command(cmd, ignore_errors=True): errors = 'ignore' try: - result = run_program(cmd, encoding='utf-8', errors=errors) + result = run_program(cmd, check=check, encoding='utf-8', errors=errors) json_data = json.loads(result.stdout) except (subprocess.CalledProcessError, json.decoder.JSONDecodeError): if not ignore_errors: