# Used to read the file /etc/zabbix_filesystems_limits.conf if it
# exists and the custom filesystems limits defined in this file.
#
-# It will return -1 if no custom limit has been defined, or the valuee
-# defined in the file.
+# It will return -1 if no custom limit has been defined, or the filesystem
+# is not defined in the file.
#
# Limit_type valid values: [percent_limit | size_limit]
#
#
# ###################################################################
-def get_local_filesystem_limits(filesystem,limit_type):
+
+def get_local_filesystem_limits(filesystem, limit_type):
defined_filesystems = dict()
config_file = '/etc/zabbix_filesystems_limits.conf'
try:
-
+
if os.path.isfile(config_file):
- fd = open(config_file,"r")
+ fd = open(config_file, "r")
for line in fd:
- line = line.replace('\n','').strip()
+ line = line.replace('\n', '').strip()
#
# Lines starting with # or empty lines are ignored.
#
-
- if line.find('#',0) == -1 and line.strip() != '':
+
+ if line.find('#', 0) == -1 and line.strip() != '':
filesystem_limit_definition = line.split('::')
#
if len(filesystem_limit_definition) == 3:
- fs = filesystem_limit_definition[0]
+ defined_fs = filesystem_limit_definition[0]
if filesystem_limit_definition[1] == '':
percent_limit = "-1"
else:
if filesystem_limit_definition[2][-1:].upper() == 'M':
size_limit = float(filesystem_limit_definition[2][:-1])*1024*1024
-
+
elif filesystem_limit_definition[2][-1:].upper() == 'G':
size_limit = float(filesystem_limit_definition[2][:-1])*1024*1024*1024
elif filesystem_limit_definition[2][-1:].upper() == 'T':
size_limit = float(filesystem_limit_definition[2][:-1])*1024*1024*1024*1024
-
+
else:
size_limit = "-1"
-
# Normalized absolutized version of the pathname
# if filesystem does not include an absolute path
- if os.path.isabs(fs) == False:
- fs = os.path.abspath(fs)
+ if not os.path.isabs(defined_fs):
+ defined_fs = os.path.abspath(defined_fs)
#
# Finds all the pathnames matching a specified
# meta-characters in brackets. For example, '[?]'
# matches the character '?'.
#
-
- expanded_files = glob.glob(fs)
+
+ expanded_files = glob.glob(defined_fs)
#
# Only mounted filesystem will be considered when
# reading filesystems limits definitions in
# /etc/zabbix_filesystems_limits.conf.
#
-
- for fs in expanded_files:
- if os.path.ismount(fs) == True:
- defined_filesystems[fs] = [percent_limit,size_limit]
-
+
+ for expanded_fs in expanded_files:
+ if os.path.ismount(expanded_fs):
+ defined_filesystems[expanded_fs] = [percent_limit, size_limit]
#
# Find out if the filesystem we are asking for exists in
else:
print "-1"
- except Exception,e:
+ except Exception, e:
print e
try:
if len(sys.argv) == 3:
- filesystem = sys.argv[1]
- limit_type = sys.argv[2]
+ fs = sys.argv[1]
+ limit_t = sys.argv[2]
+
+ get_local_filesystem_limits(fs, limit_t)
- get_local_filesystem_limits(filesystem,limit_type)
-
else:
print "Error: Wrong number of parameters"
- print 'Format: ' + sys.argv[0] + ' <filesystem> <percent_limit | size_limit>'
+ print 'Format: ' + sys.argv[0] + ' <filesystem> <percent_limit | size_limit>'
sys.exit(1)
- except Exception,e:
+ except Exception, e:
print e
sys.exit(1)