]> git.uio.no Git - uio-zabbix.git/commitdiff
Change some code to follow some python format conventions.
authorRafael Martinez Guerrero <rafael@postgresql.org.es>
Wed, 25 Nov 2015 14:28:02 +0000 (15:28 +0100)
committerRafael Martinez Guerrero <rafael@postgresql.org.es>
Wed, 25 Nov 2015 14:28:02 +0000 (15:28 +0100)
zabbix_filesystem_limits.py

index c26892520ce8463148885b3161eac5d704ef4d3c..ffca0be8a70a0e2c6cd5a443bd0e7857ea11d87a 100755 (executable)
@@ -34,8 +34,8 @@ import glob
 # 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]
 #
@@ -66,24 +66,25 @@ import glob
 #
 # ###################################################################
 
-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('::')
 
                     #
@@ -93,7 +94,7 @@ def get_local_filesystem_limits(filesystem,limit_type):
 
                     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"
@@ -105,22 +106,21 @@ def get_local_filesystem_limits(filesystem,limit_type):
                         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
@@ -131,19 +131,18 @@ def get_local_filesystem_limits(filesystem,limit_type):
                         # 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
@@ -170,7 +169,7 @@ def get_local_filesystem_limits(filesystem,limit_type):
         else:
             print "-1"
 
-    except Exception,e:
+    except Exception, e:
         print e
 
 
@@ -183,16 +182,16 @@ if __name__ == '__main__':
     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)