Ensure SMART values are shown for some disks

* smartctl can return non-zero if there are errors in the SMART logs
This commit is contained in:
2Shirt 2019-04-08 18:57:38 -07:00
parent 14ebc23b81
commit 4d9ab2215b
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 3 additions and 3 deletions

View file

@ -350,7 +350,7 @@ class DiskObj():
def get_smart_details(self): def get_smart_details(self):
"""Get data from smartctl.""" """Get data from smartctl."""
cmd = ['sudo', 'smartctl', '--all', '--json', self.path] 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 # Check for attributes
if KEY_NVME in self.smartctl: if KEY_NVME in self.smartctl:

View file

@ -4,7 +4,7 @@ import json
from functions.common import * 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. """Capture JSON content from cmd output, returns dict.
If the data can't be decoded then either an exception is raised 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' errors = 'ignore'
try: 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) json_data = json.loads(result.stdout)
except (subprocess.CalledProcessError, json.decoder.JSONDecodeError): except (subprocess.CalledProcessError, json.decoder.JSONDecodeError):
if not ignore_errors: if not ignore_errors: