File pmp-check-mongo-python3.patch of Package percona-monitoring-plugins

--- a/nagios/bin/pmp-check-mongo.py	2023-06-10 01:45:53.870322115 +0200
+++ b/nagios/bin/pmp-check-mongo.py	2023-06-10 01:57:16.639122829 +0200
@@ -23,8 +23,8 @@
 
 try:
     import pymongo
-except ImportError, e:
-    print e
+except ImportError as e:
+    print(e)
     sys.exit(2)
 
 # As of pymongo v 1.9 the SON API is part of the BSON package, therefore attempt
@@ -52,7 +52,7 @@
 def parse_options(args):
     funcList = []
     for item_name, item_type in NagiosMongoChecks.__dict__.items():
-        if type(item_type) is FunctionType and item_name.startswith("check_") and item_name is not 'check_levels':
+        if type(item_type) is FunctionType and item_name.startswith("check_") and item_name != 'check_levels':
             funcList.append(item_name)
     p = ModifiedOptionParser()
 
@@ -76,7 +76,7 @@
     # Add options for output stat file
     try:
         result = p.parse_args()
-    except OptionParsingError, e:
+    except OptionParsingError as e:
         if 'no such option' in e.msg:
             sys.exit("UNKNOWN - No such options of %s" % e.msg.split(":")[1])
         if 'invalid choice' in e.msg:
@@ -87,16 +87,16 @@
 
 def return_result(result_type, message):
     if result_type == "ok":
-        print "OK - " + message
+        print("OK - " + message)
         sys.exit(0)
     elif result_type == "critical":
-        print "CRITICAL - " + message
+        print("CRITICAL - " + message)
         sys.exit(2)
     elif result_type == "warning":
-        print "WARNING - " + message
+        print("WARNING - " + message)
         sys.exit(1)
     else:
-        print "UNKNOWN - " + message
+        print("UNKNOWN - " + message)
         sys.exit(2)
 
 
@@ -110,7 +110,7 @@
         checksObj = globals()['NagiosMongoChecks'](args)
         run_check = getattr(checksObj, check_name)
         result_type, message = run_check(args, args.warning, args.critical)
-    except Exception, e:
+    except Exception as e:
         raise
         print(traceback.extract_tb(sys.exc_info()[-1], 1))
         return_result("critical", str(e))
@@ -164,7 +164,7 @@
                 raise pymongo.errors.ConnectionFailure(self.pyMongoError or "No connection Found, did connect fail?")
             # Get fresh current_status from server
             self.current_status = self.sanatize(self.get_server_status())
-	    # user last status_filename contents as last_status
+        # user last status_filename contents as last_status
             self.get_last_status(False, self.status_filename)
         # Not yet implemented
         # self.compute_deltas()
@@ -192,15 +192,15 @@
             data = self.connection['admin'].command(pymongo.son_manipulator.SON([('serverStatus', 1)]))
         except:
             try:
-		data = self.connection['admin'].command(son.SON([('serverStatus', 1)]))
-	    except Exception, e:
-		if type(e).__name__ == "OperationFailure":
-		    sys.exit("UNKNOWN - Not authorized!")
-		else:
-		    sys.exit("UNKNOWN - Unable to run serverStatus: %s::%s" % (type(e).__name__, unicode_truncate(e.message, 45)))
+                data = self.connection['admin'].command(son.SON([('serverStatus', 1)]))
+            except Exception as e:
+                if type(e).__name__ == "OperationFailure":
+                    sys.exit("UNKNOWN - Not authorized!")
+                else:
+                    sys.exit("UNKNOWN - Unable to run serverStatus: %s::%s" % (type(e).__name__, unicode_truncate(e.message, 45)))
 
-        if self.current_status is None:
-            self.current_status = data
+                if self.current_status is None:
+                    self.current_status = data
 
         return data
 
@@ -214,15 +214,15 @@
             # Set the current status file to empty to set the aging clock
             self.save_file(self.status_filename, {})
             sys.exit("UNKNOWN - No status data present, please try again in %s seconds" % self.max_stale)
-	else:
-	    self.save_file(self.status_filename_backup, self.last_status)
-	    self.save_file(self.status_filename, self.current_status)
+        else:
+            self.save_file(self.status_filename_backup, self.last_status)
+            self.save_file(self.status_filename, self.current_status)
 
 
     def save_file(self, filename, contents):
             try:
                 pickle.dump(contents, open(filename, "wb"))
-            except Exception, e:
+            except Exception as e:
                 sys.exit("UNKNOWN - Error saving stat file %s: %s" % (filename, e.message))
 
     # TODO - Fill in all check defaults
@@ -280,19 +280,19 @@
                 con = pymongo.MongoClient(self.host, self.port, ssl=self.ssl, replicaSet=self.replicaset, serverSelectionTimeoutMS=2500)
             if (self.user and self.passwd) and not con['admin'].authenticate(self.user, self.passwd):
                 sys.exit("CRITICAL - Username and password incorrect")
-        except Exception, e:
+        except Exception as e:
             raise
             if isinstance(e, pymongo.errors.AutoReconnect) and str(e).find(" is an arbiter") != -1:
                 # We got a pymongo AutoReconnect exception that tells us we connected to an Arbiter Server
                 # This means: Arbiter is reachable and can answer requests/votes - this is all we need to know from an arbiter
-                print "OK - State: 7 (Arbiter)"
+                print("OK - State: 7 (Arbiter)")
                 sys.exit(0)
             con = None
             self.pyMongoError = str(e)
         if con is not None:
-	    try:
+            try:
                 con['admin'].command(pymongo.son_manipulator.SON([('ping', 1)]))
-            except Exception, e:
+            except Exception as e:
                 sys.exit("UNKNOWN - Unable to run commands, possible auth issue: %s" % e.message)
             self.connection_time = round(time.time() - start_time, 2)
             version = con.server_info()['version'].split('.')
@@ -390,7 +390,7 @@
     def check_queues(self, args, warning_level, critical_level):
         warning_level = warning_level or self.get_default('check_queues', 'warning')
         critical_level = critical_level or self.get_default('check_queues', 'critical')
-	currentQueue = self.current_status['globalLock']['currentQueue']
+        currentQueue = self.current_status['globalLock']['currentQueue']
         currentQueue['total'] = currentQueue['readers'] + currentQueue['writers']
         message = "Queue Sizes:  read (%d)  write(%d) total (%d)" % (currentQueue['readers'], currentQueue['writers'], currentQueue['total'])
         return self.check_levels(currentQueue['total'], warning_level, critical_level, message)
@@ -478,7 +478,7 @@
             time_range = (time.time() - start).total_seconds
             message = "Collection %s.%s  query took: %d s" % (self.database, self.collection, time_range)
             return self.check_levels(time_range, warning_level, critical_level, message)
-        except Exception, e:
+        except Exception as e:
             message = "Collection %s.%s  query FAILED: %s" % (self.database, self.collection, e)
             return "critical", message
 
@@ -491,7 +491,7 @@
         # get a  fresh status for the replset
         try:
             replset_status = self.connection['admin'].command("replSetGetStatus")
-        except Exception, e:
+        except Exception as e:
             return "critical", "Are your running with --replset? -  %s" % (e)
 
         for member in replset_status['members']:
openSUSE Build Service is sponsored by