INTRODUCTION:S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology; written as SMART) SMART is a system for monitoring and early detection of errors of storage media such as hard disks or SSDs.
All current hard drives and SSDs have SMART functionality. However, the data provided by SMART, (SMART attributes), are different from manufacturer to manufacturer
NOTE: Run IDE as administrator and SMARTMONTOOLS should be installed in the system
IMPLEMENTATION:
This python script displays the primary information about the HDD and SSD present in the system
import os
NIF = "[No Information Found]"
class DeviceRecord:
def __init__(self):
self.deviceInfo = {'Device ID':NIF,
'Device Family':NIF,
'Device Model':NIF,
'Device Serial':NIF,
'Device Firmware Version':NIF,
'Device Capacity':NIF,
'Device Sector Size':NIF,
'Device Rotation Rate':NIF,
'Device Is':NIF,
'Device ATA Version':NIF,
'Device SATA Version':NIF,
'Device SMART Support Available':False,
'Device SMART Support Enabled':False}
class SMART:
def RunSmartCtl(self, strArgs):
cmdString = "smartctl " + strArgs
output = os.popen(cmdString).read()
lines = str.splitlines(output)
return lines
def GetDeviceInfo(self, deviceId):
device = DeviceRecord()
deviceInfoLines = self.RunSmartCtl("-i " + deviceId)
bEnteredInfoSection = False
device.deviceInfo['Device ID'] = deviceId
for line2 in deviceInfoLines:
if not bEnteredInfoSection:
if line2.lower() == "=== start of information section ===":
bEnteredInfoSection = True
else:
field = str.split(line2, ":", 1)
if field[0].lower() == "model family":
device.deviceInfo['Device Family'] = field[1].strip()
elif field[0].lower() == "device model":
device.deviceInfo['Device Model'] = field[1].strip()
elif field[0].lower() == "serial number":
device.deviceInfo['Device Serial'] = field[1].strip()
elif field[0].lower() == "firmware version":
device.deviceInfo['Device Firmware Version'] = field[1].strip()
elif field[0].lower() == "user capacity":
device.deviceInfo['Device Capacity'] = field[1].strip()
elif field[0].lower() == "sector sizes":
device.deviceInfo['Device Sector Size'] = field[1].strip()
elif field[0].lower() == "rotation rate":
device.deviceInfo['Device Rotation Rate'] = field[1].strip()
elif field[0].lower() == "device is":
device.deviceInfo['Device Is'] = field[1].strip()
elif field[0].lower() == "ata version is":
device.deviceInfo['Device ATA Version'] = field[1].strip()
elif field[0].lower() == "sata version is":
device.deviceInfo['Device SATA Version'] = field[1].strip()
elif field[0].lower() == "smart support is":
temp = str.split(field[1].strip(), " ", 1)
strTemp = temp[0].strip().lower()
if strTemp == "available":
device.deviceInfo['Device SMART Support Available'] = True
elif strTemp == "unavailable":
device.deviceInfo['Device SMART Support Available'] = False
device.deviceInfo['Device SMART Support Enabled'] = False
elif strTemp == "enabled":
device.deviceInfo['Device SMART Support Enabled'] = True
elif strTemp == "disabled":
device.deviceInfo['Device SMART Support Available'] = False
return device
def main():
smart_features = SMART()
device = input("Enter device id: ")
deviceIn = smart_features.GetDeviceInfo(device)
print("Primary information")
for info in deviceIn.deviceInfo:
print(info,':',deviceIn.deviceInfo[info])
if __name__ == '__main__':
main()
OUTPUT:
Comments