Alerts if health status changes in S.M.A.R.T status of hard drives

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)

Hi Guys,

the script has a bit of a flaw with it.

The following line means all HDDs are too hot
if li1[le-1]> 29 and li1[le-1] < 45: i have changed the 29 to a 0 for us for now, but if you want to make the script better a switch/case if python allows with below say 15 being too cold?

Hi @StrobeTech
Thank you for the suggestion. We will make sure that your suggestion reaches the attention of the script development team.

I have tested, and thanks for this script! works fine, but I have an issue.

When I run this script on Hyperv (microsoft) if I have a hard disk offline (attached on virtual machine) the scripts returns an error and create an alert (failed) how can we change to ignore or read the offline disks?

@ftsolucoes,

We understand that you have some additional setups that you are testing the procedure. We will forward the result of your test to our Script Developers and get recommendation for any modifications that need to be made.

@ftsolucoes ,

We thank you for sharing the output of your test. We’ll make sure to have this result shared to ur Script Developers.

[QUOTE=ftsolucoes;n26253][/QUOTE]

Hello @ftsolucoes

We are glad to help you here. Kindly refer this script which will return you the Health status of all Hard disks available in your server :

https://scripts.comodo.com/frontend/web/topic/alerts-if-health-status-changes-in-smart-status-of-hard-drives

As shown on image, if you receive that “Health Status is Failed”, it means you need to enable it in your server setup. Enter into BIOS setup, enable SMART then run this script. Hope it make better sense.

Thank you.