Send warning to server admin if some of your hard drives is getting full.
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (C) 2014, Heikki Hyyti # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # --- configurations --- # # programs df_prog = '/bin/df' # limits to warn user bytes_available = 15000000 max_usage_percent = 85 # Locations to backup (configure these with full paths) exclude_fs = ['udev','tmpfs', 'none'] # --- Code starts --- # import subprocess def print_warning(lineparts) : print('WARNING: %s (%s) is low on space. Using %.1f of %.1f GB (%s), %.1f GB available.' % (lineparts[5], lineparts[0], float(lineparts[2]) / 1048576, float(lineparts[1]) / 1048576, lineparts[4], float(lineparts[3]) / 1048576) ) df = subprocess.Popen([df_prog], stdout=subprocess.PIPE) output = df.communicate()[0] lines = output.split("\n") for i in range(1, len(lines)): lineparts = lines[i].split() if (len(lineparts) > 5 and not lineparts[0] in exclude_fs): if (lineparts[3] <= bytes_available): print_warning(lineparts) if (int(lineparts[4].split('%')[0]) >= max_usage_percent): print_warning(lineparts)