From 994114e736f02794f278ea197c59c87aed8159b2 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 2 Feb 2021 12:55:09 +0100 Subject: [bas] Add readlink to smartctl output --- modules.d/bas-python/scripts/00collect_hw_info_json.py | 14 +++++++++++--- 1 file 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) -- cgit v1.2.3-55-g7522