#!/usr/bin/python # 2010302 jan@panoch.com # scan all connected STEC drives # with sdmcmd utility import re import subprocess from pprint import pprint def SysCmdLines (cmd): """Do system command and return lines""" p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) return p.stdout.readlines() # # main # hosts = [] for line in SysCmdLines("./smartctl-stec --scan"): line = line.rstrip() if "/dev/" in line: # print "line=[%s]" % line m = re.search(r"^(/dev/\S+) ", line) if m: host = m.group(1) hosts.append(host) # print "found host=[%s]" % (host) # pprint(hosts) # quit() serials = {} slog = '' for host in hosts: # print "host="+host sinfo = '' maxtemp = mintemp = mmin = mmax = maxspent = 0 stec = False for line in SysCmdLines("./smartctl-stec -a "+host): sinfo += line line = line.rstrip() if True or ":" in line: # print "line=[%s]" % line m = re.search(r"Serial Number:\s+(\S+)", line, re.IGNORECASE) if m: sn = m.group(1) serials[host] = sn m = re.search(r"^Max Temp\s+(\S+)", line, re.IGNORECASE) if m: maxtemp = m.group(1) m = re.search(r"^Min Temp\s+(\S+)", line, re.IGNORECASE) if m: mintemp = m.group(1) m = re.search(r"Power-On Hour when Maximum Temperature Occurred (\S+)", line, re.IGNORECASE) if m: hmax = int(m.group(1))/60 m = re.search(r"Power-On Hour when Minimum Temperature Occurred (\S+)", line, re.IGNORECASE) if m: hmin = int(m.group(1))/60 m = re.search(r"Total spent Time Over Ref (\S+)", line, re.IGNORECASE) if m: hmaxspent = int(m.group(1))/60 m = re.search(r"Vendor:\s+STEC", line, re.IGNORECASE) if m: stec = True # collect info # print "sn="+sn sinfofname = "smartctl-"+sn+".txt" if stec: print "sn="+sn+" maxtemp="+maxtemp+" mintemp="+mintemp+" hmax="+str(hmax)+" hmin="+str(hmin)+" hmaxspent="+str(hmaxspent) slog += "sn="+sn+" maxtemp="+maxtemp+" mintemp="+mintemp+" hmax="+str(hmax)+" hmin="+str(hmin)+" hmaxspent="+str(hmaxspent)+"\n" # write sinfo to file with open(sinfofname,"w") as text_file: text_file.write(sinfo) #quit() # write slog to file with open('scan_stec_ssd_smartctl.log',"a") as text_file: text_file.write(slog)