diff options
author | Jannik Schönartz | 2021-02-02 12:55:09 +0100 |
---|---|---|
committer | Jannik Schönartz | 2021-02-02 12:55:09 +0100 |
commit | 994114e736f02794f278ea197c59c87aed8159b2 (patch) | |
tree | bff06325c48377191e24ce7276600fef3e615e7a | |
parent | Handle stderr with valid returncode 0 and add paramter for printing the json (diff) | |
download | systemd-init-994114e736f02794f278ea197c59c87aed8159b2.tar.gz systemd-init-994114e736f02794f278ea197c59c87aed8159b2.tar.xz systemd-init-994114e736f02794f278ea197c59c87aed8159b2.zip |
[bas] Add readlink to smartctl output
-rwxr-xr-x | modules.d/bas-python/scripts/00collect_hw_info_json.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/modules.d/bas-python/scripts/00collect_hw_info_json.py b/modules.d/bas-python/scripts/00collect_hw_info_json.py index fc10eb42..9eea9ca8 100755 --- a/modules.d/bas-python/scripts/00collect_hw_info_json.py +++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py @@ -47,17 +47,25 @@ def get_dmidecode(): else: return [] +# Get the readlink -f output +def get_readlink(link): + _readlink = run_subprocess('readlink -f ' + link) + return _readlink + # Get smartctl output in json format def get_smartctl(): + diskdir = '/dev/disk/by-path/' # Get and filter all disks - disks = listdir('/dev/disk/by-path/') + disks = listdir(diskdir) filteredDisks = [i for i in disks if (not "-part" in i) and (not "-usb-" in i)] smartctl = {} for d in filteredDisks: - output = run_subprocess('smartctl -x --json /dev/disk/by-path/' + d) + output = run_subprocess('smartctl -x --json ' + diskdir + d) if isinstance(output, str): try: - smartctl[d] = json.loads(output) + disk = json.loads(output) + disk['readlink'] = get_readlink(diskdir + d).rstrip() + smartctl[d] = disk except ValueError as e: print('smartctl failed with error:') print(e) |