postgres_plugin: remove sensitive information from error
Ilya committed
Mar 3, 2017 at 23:12 UTC
46df800df1d4308a6f368bba3c46f9e02c5328fb
1 file changed
+9
-6
python.d/postgres.chart.py
+9
-6
@@ -262,16 +262,18 @@ class Service(SimpleService):
262
self.connection = psycopg2.connect(**params)
263
self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT)
264
self.connection.set_session(readonly=True)
265
- except OperationalError:
266
- return False
267
- return True
265
+ except OperationalError as error:
266
+ return False, str(error)
267
+ return True, True
268
269
def check(self):
270
if not PSYCOPG2:
271
self.error('\'python-psycopg2\' module is needed to use postgres.chart.py')
272
return False
273
- if not self._connect():
274
- self.error('Can\'t connect to %s' % str(self.configuration))
273
+ result, error = self._connect()
274
+ if not result:
275
+ conf = dict([(k, (lambda k, v: v if k != 'password' else '*****')(k, v)) for k, v in self.configuration.items()])
276
+ self.error('Failed to connect to %s. Error: %s' % (str(conf), error))
277
return False
278
try:
279
cursor = self.connection.cursor()
@@ -307,7 +309,8 @@ class Service(SimpleService):
309
add_database_lock_chart_(order=self.order, definitions=self.definitions, database_name=database_name)
310
311
def _get_data(self):
310
- if self._connect():
312
+ result, error = self._connect()
313
+ if result:
314
cursor = self.connection.cursor(cursor_factory=DictCursor)
315
try:
316
self.data.update(self.locks_zeroed)