From aa66f8d615a69ff5d07ec66172d73b67f61667cc Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 19 Aug 2023 13:55:43 +0200 Subject: [PATCH] Handle some raw values which aren't simple integers --- clients/record_smart | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/clients/record_smart b/clients/record_smart index 448290e..f5348bf 100755 --- a/clients/record_smart +++ b/clients/record_smart @@ -20,8 +20,14 @@ for ln in p.stdout.splitlines(): elif state == 1 and ln == "": state = 2 elif state == 1: - (id, attribute_name, flag, value, worst, thresh, type, updated, when_failed, raw_value) = ln.split() + (id, attribute_name, flag, value, worst, thresh, type, updated, when_failed, raw_value) = ln.split(None, 9) + if attribute_name == "Command_Timeout": + # This is a tuple of three values and I don't know what they mean + # so I just skip them. + # I guess I could just record them as smart_command_timeout_1, + # smart_command_timeout_2 and smart_command_timeout_3 ... + continue if "_Ct" in attribute_name or "_Count" in attribute_name or "_Cnt" in attribute_name: unit = "count" elif "_Hours" in attribute_name: @@ -33,11 +39,23 @@ for ln in p.stdout.splitlines(): else: unit = "unknown" + if unit == "°C": + # Sometimes there is extra information included - just ignore that. + value = int(raw_value.split()[0]) + elif unit == "hours": + if m := re.match(r"([0-9]+)h\+([0-9]+)m\+([0-9.]+)s", raw_value): + # e.g. 60633h+54m+11.557s + value = (int(m.group(1)) * 3600 + int(m.group(2)) * 60 + float(m.group(2))) / 3600 + else: + value = int(raw_value) + else: + value = int(raw_value) + report0.append( { "measure": "smart_" + attribute_name.lower(), "unit": unit, - "value": int(raw_value), + "value": value, }) now = time.time() report = [