-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from zeroquinc:disk-space
feature: add disk space voice channel
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import subprocess | ||
|
||
from utils.custom_logger import logger | ||
|
||
def get_disk_space() -> str: | ||
target_partition = '/dev/sdb' | ||
|
||
try: | ||
result = subprocess.run(['df', '-BG'], capture_output=True, text=True, check=True) | ||
except subprocess.CalledProcessError as e: | ||
return f"Error running df command: {e}" | ||
|
||
lines = result.stdout.splitlines() | ||
if len(lines) < 2: | ||
return "Unexpected output format from df command" | ||
|
||
for line in lines[1:]: | ||
parts = line.split() | ||
if parts[0] == target_partition: | ||
headers = lines[0].split() | ||
values = line.split() | ||
if "Available" in headers and "1G-blocks" in headers: | ||
available_space_index = headers.index("Available") | ||
total_space_index = headers.index("1G-blocks") | ||
elif "Avail" in headers and "Size" in headers: # Some versions of 'df' abbreviate 'Available' as 'Avail' | ||
available_space_index = headers.index("Avail") | ||
total_space_index = headers.index("Size") | ||
else: | ||
return "Could not find space information in df output" | ||
|
||
available_space_gb = values[available_space_index].rstrip('G') | ||
total_space_gb = values[total_space_index].rstrip('G') | ||
logger.info(f"Available space: {available_space_gb} GB, Total space: {total_space_gb} GB") | ||
return f"{available_space_gb}GB / {total_space_gb}GB" | ||
|
||
return f"No data found for {target_partition}" |