Debian Codegraph @

debian/patches/percona-nagios-plugins/python2to3

raw
1 Index: pkg-nagios-plugins-contrib/percona-nagios-plugins/nagios/bin/pmp-check-aws-rds.py
2 ===================================================================
3 --- pkg-nagios-plugins-contrib.orig/percona-nagios-plugins/nagios/bin/pmp-check-aws-rds.py
4 +++ pkg-nagios-plugins-contrib/percona-nagios-plugins/nagios/bin/pmp-check-aws-rds.py
5 @@ -1,4 +1,4 @@
6 -#!/usr/bin/env python
7 +#!/usr/bin/env python3
8 """Nagios plugin for Amazon RDS monitoring.
9
10 This program is part of $PROJECT_NAME$
11 @@ -98,7 +98,7 @@ def debug(val):
12 """Debugging output"""
13 global options
14 if options.debug:
15 - print 'DEBUG: %s' % val
16 + print('DEBUG: %s' % val)
17
18
19 def main():
20 @@ -166,7 +166,7 @@ def main():
21 parser.add_option('-i', '--ident', help='DB instance identifier')
22 parser.add_option('-p', '--print', help='print status and other details for a given DB instance',
23 action='store_true', default=False, dest='printinfo')
24 - parser.add_option('-m', '--metric', help='metric to check: [%s]' % ', '.join(metrics.keys()))
25 + parser.add_option('-m', '--metric', help='metric to check: [%s]' % ', '.join(list(metrics.keys())))
26 parser.add_option('-w', '--warn', help='warning threshold')
27 parser.add_option('-c', '--crit', help='critical threshold')
28 parser.add_option('-u', '--unit', help='unit of thresholds for "storage" and "memory" metrics: [%s].'
29 @@ -193,7 +193,7 @@ def main():
30 sys.exit()
31 elif options.db_list:
32 info = rds.get_list()
33 - print 'List of all DB instances in %s region(s):' % (options.region,)
34 + print('List of all DB instances in %s region(s):' % (options.region,))
35 pprint.pprint(info)
36 sys.exit()
37 elif not options.ident:
38 @@ -204,10 +204,10 @@ def main():
39 if info:
40 pprint.pprint(vars(info))
41 else:
42 - print 'No DB instance "%s" found on your AWS account and %s region(s).' % (options.ident, options.region)
43 + print('No DB instance "%s" found on your AWS account and %s region(s).' % (options.ident, options.region))
44
45 sys.exit()
46 - elif not options.metric or options.metric not in metrics.keys():
47 + elif not options.metric or options.metric not in list(metrics.keys()):
48 parser.print_help()
49 parser.error('Metric is not set or not valid.')
50 elif not options.warn and options.metric != 'status':
51 @@ -327,7 +327,7 @@ def main():
52 try:
53 storage = db_classes[info.instance_class]
54 except:
55 - print 'Unknown DB instance class "%s"' % info.instance_class
56 + print('Unknown DB instance class "%s"' % info.instance_class)
57 sys.exit(CRITICAL)
58
59 free = '%.2f' % (free / 1024 ** 3)
60 @@ -353,12 +353,12 @@ def main():
61
62 # Final output
63 if status != UNKNOWN and perf_data:
64 - print '%s %s | %s' % (short_status[status], note, perf_data)
65 + print('%s %s | %s' % (short_status[status], note, perf_data))
66 elif status == UNKNOWN and not options.forceunknown:
67 - print '%s %s | null' % ('OK', note)
68 + print('%s %s | null' % ('OK', note))
69 sys.exit(0)
70 else:
71 - print '%s %s' % (short_status[status], note)
72 + print('%s %s' % (short_status[status], note))
73
74 sys.exit(status)
75
76 Index: pkg-nagios-plugins-contrib/percona-nagios-plugins/nagios/bin/pmp-check-mongo.py
77 ===================================================================
78 --- pkg-nagios-plugins-contrib.orig/percona-nagios-plugins/nagios/bin/pmp-check-mongo.py
79 +++ pkg-nagios-plugins-contrib/percona-nagios-plugins/nagios/bin/pmp-check-mongo.py
80 @@ -1,4 +1,4 @@
81 -#!/usr/bin/env python2.7
82 +#!/usr/bin/env python3
83 """MongoDB Nagios check script
84
85 This program is part of $PROJECT_NAME$
86 @@ -23,8 +23,8 @@ from types import FunctionType
87
88 try:
89 import pymongo
90 -except ImportError, e:
91 - print e
92 +except ImportError as e:
93 + print(e)
94 sys.exit(2)
95
96 # As of pymongo v 1.9 the SON API is part of the BSON package, therefore attempt
97 @@ -51,7 +51,7 @@ def unicode_truncate(s, length, encoding
98
99 def parse_options(args):
100 funcList = []
101 - for item_name, item_type in NagiosMongoChecks.__dict__.items():
102 + for item_name, item_type in list(NagiosMongoChecks.__dict__.items()):
103 if type(item_type) is FunctionType and item_name.startswith("check_") and item_name is not 'check_levels':
104 funcList.append(item_name)
105 p = ModifiedOptionParser()
106 @@ -76,7 +76,7 @@ def parse_options(args):
107 # Add options for output stat file
108 try:
109 result = p.parse_args()
110 - except OptionParsingError, e:
111 + except OptionParsingError as e:
112 if 'no such option' in e.msg:
113 sys.exit("UNKNOWN - No such options of %s" % e.msg.split(":")[1])
114 if 'invalid choice' in e.msg:
115 @@ -87,16 +87,16 @@ def parse_options(args):
116
117 def return_result(result_type, message):
118 if result_type == "ok":
119 - print "OK - " + message
120 + print("OK - " + message)
121 sys.exit(0)
122 elif result_type == "critical":
123 - print "CRITICAL - " + message
124 + print("CRITICAL - " + message)
125 sys.exit(2)
126 elif result_type == "warning":
127 - print "WARNING - " + message
128 + print("WARNING - " + message)
129 sys.exit(1)
130 else:
131 - print "UNKNOWN - " + message
132 + print("UNKNOWN - " + message)
133 sys.exit(2)
134
135
136 @@ -110,9 +110,9 @@ def check(args, check_name):
137 checksObj = globals()['NagiosMongoChecks'](args)
138 run_check = getattr(checksObj, check_name)
139 result_type, message = run_check(args, args.warning, args.critical)
140 - except Exception, e:
141 + except Exception as e:
142 raise
143 - print(traceback.extract_tb(sys.exc_info()[-1], 1))
144 + print((traceback.extract_tb(sys.exc_info()[-1], 1)))
145 return_result("critical", str(e))
146 return_result(result_type, message)
147
148 @@ -193,7 +193,7 @@ class NagiosMongoChecks:
149 except:
150 try:
151 data = self.connection['admin'].command(son.SON([('serverStatus', 1)]))
152 - except Exception, e:
153 + except Exception as e:
154 if type(e).__name__ == "OperationFailure":
155 sys.exit("UNKNOWN - Not authorized!")
156 else:
157 @@ -222,7 +222,7 @@ class NagiosMongoChecks:
158 def save_file(self, filename, contents):
159 try:
160 pickle.dump(contents, open(filename, "wb"))
161 - except Exception, e:
162 + except Exception as e:
163 sys.exit("UNKNOWN - Error saving stat file %s: %s" % (filename, e.message))
164
165 # TODO - Fill in all check defaults
166 @@ -280,19 +280,19 @@ class NagiosMongoChecks:
167 con = pymongo.MongoClient(self.host, self.port, ssl=self.ssl, replicaSet=self.replicaset, serverSelectionTimeoutMS=2500)
168 if (self.user and self.passwd) and not con['admin'].authenticate(self.user, self.passwd):
169 sys.exit("CRITICAL - Username and password incorrect")
170 - except Exception, e:
171 + except Exception as e:
172 raise
173 if isinstance(e, pymongo.errors.AutoReconnect) and str(e).find(" is an arbiter") != -1:
174 # We got a pymongo AutoReconnect exception that tells us we connected to an Arbiter Server
175 # This means: Arbiter is reachable and can answer requests/votes - this is all we need to know from an arbiter
176 - print "OK - State: 7 (Arbiter)"
177 + print("OK - State: 7 (Arbiter)")
178 sys.exit(0)
179 con = None
180 self.pyMongoError = str(e)
181 if con is not None:
182 try:
183 con['admin'].command(pymongo.son_manipulator.SON([('ping', 1)]))
184 - except Exception, e:
185 + except Exception as e:
186 sys.exit("UNKNOWN - Unable to run commands, possible auth issue: %s" % e.message)
187 self.connection_time = round(time.time() - start_time, 2)
188 version = con.server_info()['version'].split('.')
189 @@ -478,7 +478,7 @@ class NagiosMongoChecks:
190 time_range = (time.time() - start).total_seconds
191 message = "Collection %s.%s query took: %d s" % (self.database, self.collection, time_range)
192 return self.check_levels(time_range, warning_level, critical_level, message)
193 - except Exception, e:
194 + except Exception as e:
195 message = "Collection %s.%s query FAILED: %s" % (self.database, self.collection, e)
196 return "critical", message
197
198 @@ -491,7 +491,7 @@ class NagiosMongoChecks:
199 # get a fresh status for the replset
200 try:
201 replset_status = self.connection['admin'].command("replSetGetStatus")
202 - except Exception, e:
203 + except Exception as e:
204 return "critical", "Are your running with --replset? - %s" % (e)
205
206 for member in replset_status['members']: