Skip to content

Commit f1e4c84

Browse files
committed
MySQLService: "queries" finding preference changed (1.module conf 2.module code)
1 parent 5bb65ad commit f1e4c84

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

python.d/python_modules/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,8 @@ def __init__(self, configuration=None, name=None):
947947
SimpleService.__init__(self, configuration=configuration, name=name)
948948
self.__connection = None
949949
self.conn_properties = dict()
950-
self.queries = self.configuration.get('queries', dict())
950+
self.__queries = self.configuration.get('queries', dict())
951+
self.queries = dict()
951952

952953
def __connect(self):
953954
try:
@@ -1001,6 +1002,8 @@ def is_valid_query(query):
10011002
self.error('MySQLdb or PyMySQL module is needed to use mysql.chart.py plugin')
10021003
return False
10031004

1005+
# Preference: 1. "queries" from the configuration file 2. "queries" from the module
1006+
self.queries = self.__queries or self.queries
10041007
# Check if "self.queries" exist, not empty and all queries are in valid format
10051008
self.queries = is_valid_queries_dict(self.queries, self.error)
10061009
if not self.queries:
@@ -1044,9 +1047,10 @@ def _get_raw_data(self, description=None):
10441047
return None
10451048

10461049
raw_data = dict()
1050+
queries = dict(self.queries)
10471051
try:
10481052
with self.__connection as cursor:
1049-
for name, query in self.queries.items():
1053+
for name, query in queries.items():
10501054
try:
10511055
cursor.execute(query)
10521056
except (MySQLdb.ProgrammingError, MySQLdb.OperationalError) as error:
@@ -1068,7 +1072,5 @@ def _get_raw_data(self, description=None):
10681072

10691073
@staticmethod
10701074
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])

0 commit comments

Comments
 (0)