hi,
This script will help you to view your hard drive’s S.M.A.R.T(Self-Monitoring, Analysis, and Reporting Technology) data.
script generates the alerts if any of the condition is met i.e (Health status is " Failed ", Temperature is high and changes in Attribute conditions of Hard Drive)
Note: This script uses the open source smart monitoring tool.
This Script should run as Custom monitoring for better output
import urllib
import os
import sys
import re
def alert(arg):
sys.stderr.write("%d%d%d" % (arg, arg, arg))
def information(workdir):
ale=0
li=[]
os.chdir(workdir)
out=os.popen("smartctl -a /dev/sda").read()
for i in out:
if 'Read SMART Log Directory failed:' in i:
break
if 'SMART support is: Available - device has SMART capability.' in out:
print "SMART Support is Available"
if 'SMART support is: Enabled' in out :
print "SMART support is enabled"
if 'SMART support is: Disabled ' in out :
print 'SMART support is disabled it is Enabling '
os.popen('smartctl -s on /dev/sda')
print "SMART SUPPORT is Enabled"
if 'SMART overall-health self-assessment test result: PASSED' in out:
print "Health status Passed"
else :
print "*****"
print "Health status is Failed"
ale=ale+1
out1=os.popen('smartctl -A /dev/sda').read()
reg=re.findall('(O\w{6}\_\U\w{12}.*)',out1)
li1=[int(s) for s in reg[0].split() if s.isdigit()]
le=len(li1)
if li1[le-1]>0:
print "*****"
print "Please check hard drive"
print reg[0]
ale=ale+1
else :
print "Offline Uncorrectable Attribute is passed "
reg=re.findall('(C\w{6}\_P.*)',out1)
li1=[int(s) for s in reg[0].split() if s.isdigit()]
le=len(li1)
if li1[le-1]>0:
print "*****"
print "Please check hard drive"
print reg[0]
ale=ale+1
else :
print "Current Pending Sector Attribute is Passed"
reg=re.findall('(A\w{6}\_T.*)',out1)
li1=[int(s) for s in reg[0].split() if s.isdigit()]
le=len(li1)
if li1[le-1]> 29 and li1[le-1] < 45:
print "Temperature of Hard drive is " +str(li1[le-1])
else:
print "*****"
print "Temperature of Hard drive is " +str(li1[le-1])
print "Temperature is too High"
ale=ale+1
print "
"
print out
if ale>0:
alert(1)
else :
print "Your HARD DISK is safe"
alert(0)
def downloadFile(DownTo, fromURL):
try:
fileName = fromURL.split('/')[-1]
DownTo = os.path.join(DownTo, fileName)
with open(DownTo, 'wb') as f:
f.write(urllib.urlopen(fromURL).read())
if os.path.isfile(DownTo):
return '{} - {}KB'.format(DownTo, os.path.getsize(DownTo)/1000)
except:
return 'Please Check URL or Download Path!'
workdir=os.environ['PROGRAMDATA']+r'\c1_temp'
if not os.path.isdir(workdir):
os.mkdir(workdir)
url='https://patchportal.one.comodo.com/portal/packages/spm/Wise Force Deleter/x86/smartctl.exe'
if not os.path.exists(workdir+r'\smartctl.exe'):
print "The tool is downloading"
downloadFile(workdir,url)
information(workdir)
else:
information(workdir)
20170630-Imported-SMART-Hard-Drive-monitoring.json (4.38 KB)