@cryptotaxi247 / netdata-1 / commits / 16de07432

web_log: minor fixes

Ilya committed May 21, 2017 at 00:46 UTC 16de074329f87e9bf7dc76417dfa2aed298d3638
1 file changed +33 -36
python.d/web_log.chart.py
+33 -36
@@ -222,47 +222,44 @@ class Service(LogService):
222 return find_regex_return(msg='Pattern compile error: %s' % str(error))
223
224 match = regex.search(last_line)
225 - if match:
226 - match_dict = match.groupdict() or None
227 - else:
225 + if not match:
226 return find_regex_return(msg='Custom log: pattern search FAILED')
227
228 + match_dict = match.groupdict() or None
229 if match_dict is None:
231 - find_regex_return(msg='Custom log: search OK but contains no named subgroups'
232 - ' (you need to use ?P<subgroup_name>)')
230 + return find_regex_return(msg='Custom log: search OK but contains no named subgroups'
231 + ' (you need to use ?P<subgroup_name>)')
232 + mandatory_dict = {'address': r'[\da-f.:]+',
233 + 'code': r'[1-9]\d{2}',
234 + 'method': r'[A-Z]+',
235 + 'bytes_sent': r'\d+|-'}
236 + optional_dict = {'resp_length': r'\d+',
237 + 'resp_time': r'[\d.]+',
238 + 'http_version': r'\d\.\d'}
239 +
240 + mandatory_values = set(mandatory_dict) - set(match_dict)
241 + if mandatory_values:
242 + return find_regex_return(msg='Custom log: search OK but some mandatory keys (%s) are missing'
243 + % list(mandatory_values))
244 + for key in mandatory_dict:
245 + if not re.search(mandatory_dict[key], match_dict[key]):
246 + return find_regex_return(msg='Custom log: can\'t parse "%s": %s'
247 + % (key, match_dict[key]))
248 +
249 + optional_values = set(optional_dict) & set(match_dict)
250 + for key in optional_values:
251 + if not re.search(optional_dict[key], match_dict[key]):
252 + return find_regex_return(msg='Custom log: can\'t parse "%s": %s'
253 + % (key, match_dict[key]))
254 +
255 + dot_in_time = '.' in match_dict.get('resp_time', '')
256 + if dot_in_time:
257 + self.resp_time_func = lambda time: time * (resp_time_func or 1000000)
258 else:
234 - mandatory_dict = {'address': r'[\da-f.:]+',
235 - 'code': r'[1-9]\d{2}',
236 - 'method': r'[A-Z]+',
237 - 'bytes_sent': r'\d+|-'}
238 - optional_dict = {'resp_length': r'\d+',
239 - 'resp_time': r'[\d.]+',
240 - 'http_version': r'\d\.\d'}
241 -
242 - mandatory_values = set(mandatory_dict) - set(match_dict)
243 - if mandatory_values:
244 - return find_regex_return(msg='Custom log: search OK but some mandatory keys (%s) are missing'
245 - % list(mandatory_values))
246 - else:
247 - for key in mandatory_dict:
248 - if not re.search(mandatory_dict[key], match_dict[key]):
249 - return find_regex_return(msg='Custom log: can\'t parse "%s": %s'
250 - % (key, match_dict[key]))
251 -
252 - optional_values = set(optional_dict) & set(match_dict)
253 - for key in optional_values:
254 - if not re.search(optional_dict[key], match_dict[key]):
255 - return find_regex_return(msg='Custom log: can\'t parse "%s": %s'
256 - % (key, match_dict[key]))
257 -
258 - dot_in_time = '.' in match_dict.get('resp_time', '')
259 - if dot_in_time:
260 - self.resp_time_func = lambda time: time * (resp_time_func or 1000000)
261 - else:
262 - self.resp_time_func = lambda time: time * (resp_time_func or 1)
259 + self.resp_time_func = lambda time: time * (resp_time_func or 1)
260
264 - self.regex = regex
265 - return find_regex_return(match_dict=match_dict)
261 + self.regex = regex
262 + return find_regex_return(match_dict=match_dict)
263
264 def find_regex(self, last_line):
265 """