From 1a7003fef2cbb435663469cc21a2f10f2a684bfe Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 19 Aug 2023 13:13:09 +0200 Subject: [PATCH] Record raw smart vendor attributes --- clients/record_smart | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 clients/record_smart diff --git a/clients/record_smart b/clients/record_smart new file mode 100755 index 0000000..448290e --- /dev/null +++ b/clients/record_smart @@ -0,0 +1,60 @@ +#!/usr/bin/python3 +import argparse +import re +import subprocess +import time + +import ltsdb_record + +ap = argparse.ArgumentParser() +ap.add_argument("device") +args = ap.parse_args() + +p = subprocess.run(["/usr/sbin/smartctl", "-A", args.device], + stdout=subprocess.PIPE, universal_newlines=True) +report0 = [] +state = 0 +for ln in p.stdout.splitlines(): + if state == 0 and ln.startswith("ID# ATTRIBUTE_NAME"): + state = 1 + 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() + + if "_Ct" in attribute_name or "_Count" in attribute_name or "_Cnt" in attribute_name: + unit = "count" + elif "_Hours" in attribute_name: + unit = "hours" + elif "Total_LBAs_Written" in attribute_name: + unit = "blocks" + elif "Temperature_Cel" in attribute_name: + unit = "°C" + else: + unit = "unknown" + + report0.append( + { + "measure": "smart_" + attribute_name.lower(), + "unit": unit, + "value": int(raw_value), + }) +now = time.time() +report = [ + { + "description": { + "hostname": ltsdb_record.node, + "device": args.device, + "measure": r["measure"], + "unit": r["unit"], + }, + "data": [ + [now, r["value"]] + ] + } + for r in report0 +] + +success = ltsdb_record.record_observations(report) +exit(1 - success) +