#To define a particular parameter, replace the 'parameterName' inside itsm.getParameter('parameterName') with that parameter's name
import time
import ctypes
import os
from subprocess import PIPE,Popen
import sys

start=time.time()

def alert(arg):
    return sys.stderr.write("%d%d%d" % (arg, arg, arg))

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

hn=os.popen("hostname").read().strip()

with disable_file_system_redirection():
    process1=Popen("wmic diskdrive get status,caption",stdout=PIPE,stderr=PIPE)
    r1,e1=process1.communicate()
    if e1:
        print e1
    else:
        r1=r1.splitlines()
        hdd=[i.strip() for i in r1[1:]]
        for i in hdd:
            if i!="":
                if "OK" in i:
                    alert(0)
                else:
                    print("Alert for {0}: Host is not reporting healthy SMART Status.".format(hn))
                    print(i)
                    alert(1)
                    
    

end=time.time()
print("Execution Time:%s"%(end-start))