Commit d5e8fb0a authored by HERBERT Ryan's avatar HERBERT Ryan added disk space check utility

This function can be called when one needs to check disk space. If the
disk space is below a specified percentage threshhold, the function
notifies the system administrators.
A boolean is returned to indicate the disk space situation.
parent 753e78ca
......@@ -410,3 +410,17 @@ def log_links(s):
s = '%s<a class="loglink pointer" %s>%s</a>%s' % (s[:start], link, s[start:end], s[end:])
return s
def check_enough_space(directory):
import subprocess
df = subprocess.Popen(["df", directory], stdout=subprocess.PIPE)
output = df.communicate()[0]
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
available = int(available)
size = int(size)
result = available < (size * (defs.FS_LOCK_THRESHHOLD/100))
if not result:
subject="[Vidjil] Server space",
message="The space in directory %s has passed below %d\%." % directory, defs.FS_LOCK_THRESHHOLD)
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment