From: Ilya Date: Fri, 3 Mar 2017 14:12:58 +0000 (+0900) Subject: postgres_plugin: remove sensitive information from error X-Git-Tag: ab-debian_0.20170311.01-0ab1~1^2~14^2 X-Git-Url: https://arthur.barton.de/gitweb/?p=netdata.git;a=commitdiff_plain;h=46df800df1d4308a6f368bba3c46f9e02c5328fb;hp=ea1bda4d613ef9dcb1c230327cccfcbfca6a1a43 postgres_plugin: remove sensitive information from error --- diff --git a/python.d/postgres.chart.py b/python.d/postgres.chart.py index 832092e1..d359bb4f 100644 --- a/python.d/postgres.chart.py +++ b/python.d/postgres.chart.py @@ -262,16 +262,18 @@ class Service(SimpleService): self.connection = psycopg2.connect(**params) self.connection.set_isolation_level(extensions.ISOLATION_LEVEL_AUTOCOMMIT) self.connection.set_session(readonly=True) - except OperationalError: - return False - return True + except OperationalError as error: + return False, str(error) + return True, True def check(self): if not PSYCOPG2: self.error('\'python-psycopg2\' module is needed to use postgres.chart.py') return False - if not self._connect(): - self.error('Can\'t connect to %s' % str(self.configuration)) + result, error = self._connect() + if not result: + conf = dict([(k, (lambda k, v: v if k != 'password' else '*****')(k, v)) for k, v in self.configuration.items()]) + self.error('Failed to connect to %s. Error: %s' % (str(conf), error)) return False try: cursor = self.connection.cursor() @@ -307,7 +309,8 @@ class Service(SimpleService): add_database_lock_chart_(order=self.order, definitions=self.definitions, database_name=database_name) def _get_data(self): - if self._connect(): + result, error = self._connect() + if result: cursor = self.connection.cursor(cursor_factory=DictCursor) try: self.data.update(self.locks_zeroed)