Skip to content

Commit

Permalink
Merge pull request #3 from danielcbit/patch-1
Browse files Browse the repository at this point in the history
Fix NVMe drive detection and Temp Regex
  • Loading branch information
natankeddem authored Mar 30, 2024
2 parents c5644f8 + 17d9485 commit 5ce08c1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions hush/hardware/smart.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def get_drive_list(self):
drive_paths = list()
try:
result = await self.ssh.shell("fdisk -l")
drive_paths = re.findall(r"Disk (\/dev\/sd[a-z]+|\/dev\/nvm[0-9]+n[0-9]+)", result.stdout)
drive_paths = re.findall(r"Disk (\/dev\/sd[a-z]+|\/dev\/nvme[0-9]+n[0-9]+)", result.stdout)
except Exception as e:
logger.info(f"{self} failed to get drive list:")
logger.info(f"result = {result}")
Expand All @@ -24,13 +24,14 @@ async def get_drive_list(self):

async def get_drive_temp(self, drive_path):
try:
result = await self.ssh.shell(f'smartctl -x {drive_path} | grep -E "Temp|Cel|Cur|temp|cel|cur"')
temp = re.search(r"Current(?:\sDrive)?\sTemperature:\s*(\d+)", result.stdout)
if temp is not None and temp.lastindex == 1:
return float(temp.group(1))
else:
logger.info(f"{self.hostname} failed to get drive temperature {drive_path}:")
logger.info(f"result = {result}")
result = await self.ssh.shell(f'smartctl -x {drive_path} | grep -E "Temperature|temperature"')
for line in result.stdout_lines:
temp = re.search(r"^(?:Current(?:\sDrive)?\s)?Temperature:\s*(\d+)", line)
if temp is not None and temp.lastindex == 1:
return float(temp.group(1))
logger.info(f"{self.hostname} failed to get drive temperature {drive_path}:")
logger.info(f"result = {result}")
return None
except Exception as e:
logger.info(f"{self.hostname} failed to get drive temperature {drive_path}:")
logger.info(f"result = {result}")
Expand Down

0 comments on commit 5ce08c1

Please sign in to comment.