@cryptotaxi247 / netdata-1 / commits / f1e4c847e

MySQLService: "queries" finding preference changed (1.module conf 2.module code)

Ilya committed Mar 11, 2017 at 01:53 UTC f1e4c847ef213d08bf323267c31df03ed70f4260
1 file changed +8 -6
python.d/python_modules/base.py
+8 -6
@@ -947,7 +947,8 @@ class MySQLService(SimpleService):
947 SimpleService.__init__(self, configuration=configuration, name=name)
948 self.__connection = None
949 self.conn_properties = dict()
950 - self.queries = self.configuration.get('queries', dict())
950 + self.__queries = self.configuration.get('queries', dict())
951 + self.queries = dict()
952
953 def __connect(self):
954 try:
@@ -1001,6 +1002,8 @@ class MySQLService(SimpleService):
1002 self.error('MySQLdb or PyMySQL module is needed to use mysql.chart.py plugin')
1003 return False
1004
1005 + # Preference: 1. "queries" from the configuration file 2. "queries" from the module
1006 + self.queries = self.__queries or self.queries
1007 # Check if "self.queries" exist, not empty and all queries are in valid format
1008 self.queries = is_valid_queries_dict(self.queries, self.error)
1009 if not self.queries:
@@ -1044,9 +1047,10 @@ class MySQLService(SimpleService):
1047 return None
1048
1049 raw_data = dict()
1050 + queries = dict(self.queries)
1051 try:
1052 with self.__connection as cursor:
1049 - for name, query in self.queries.items():
1053 + for name, query in queries.items():
1054 try:
1055 cursor.execute(query)
1056 except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as error:
@@ -1068,7 +1072,5 @@ class MySQLService(SimpleService):
1072
1073 @staticmethod
1074 def __is_error_critical(err_class, err_text):
1071 - def in_not_in(value):
1072 - return value[1:] in err_text if value[0] == '+' else value[1:] not in err_text
1073 -
1074 - return err_class == MySQLdb.OperationalError and all([in_not_in('-denied'), in_not_in('-Unknown column')])
1075 + return err_class == MySQLdb.OperationalError and all(['denied' not in err_text,
1076 + 'Unknown column' not in err_text])