def check(self): last_line = read_last_line(self.log_path) if not last_line: return False self.storage['unique_all_time'] = list() self.storage['regex'] = re.compile( r'[0-9.]+\s+(?P<duration>[0-9]+)' r' (?P<client_address>[\da-f.:]+)' r' (?P<squid_code>[A-Z_]+)/' r'(?P<http_code>[0-9]+)' r' (?P<bytes>[0-9]+)' r' (?P<method>[A-Z_]+)' r' (?P<url>[^ ]+)' r' (?P<user>[^ ]+)' r' (?P<hier_code>[A-Z_]+)/[\da-z.:-]+' r' (?P<mime_type>[A-Za-z-]*)') match = self.storage['regex'].search(last_line) if not match: self.error('Regex not matches (%s)' % self.storage['regex'].pattern) return False self.storage['dynamic'] = { 'http_code': { 'chart': 'squid_detailed_response_codes', 'func_dim_id': None, 'func_dim': None }, 'hier_code': { 'chart': 'squid_hier_code', 'func_dim_id': None, 'func_dim': lambda v: v.replace('HIER_', '') }, 'method': { 'chart': 'squid_method', 'func_dim_id': None, 'func_dim': None }, 'mime_type': { 'chart': 'squid_mime_type', 'func_dim_id': lambda v: str.lower(v) if str.lower(v) in MIME_TYPES else 'unknown', 'func_dim': None } } if not self.configuration.get('all_time', True): self.order.remove('squid_clients_all') return True
def check(self): last_line = read_last_line(self.log_path) if not last_line: return False self.storage['unique_all_time'] = list() self.storage['regex'] = re.compile(r'[0-9.]+\s+(?P<duration>[0-9]+)' r' (?P<client_address>[\da-f.:]+)' r' (?P<squid_code>[A-Z_]+)/' r'(?P<http_code>[0-9]+)' r' (?P<bytes>[0-9]+)' r' (?P<method>[A-Z_]+)' r' (?P<url>[^ ]+)' r' (?P<user>[^ ]+)' r' (?P<hier_code>[A-Z_]+)/[\da-z.:-]+' r' (?P<mime_type>[A-Za-z-]*)') match = self.storage['regex'].search(last_line) if not match: self.error('Regex not matches (%s)' % self.storage['regex'].pattern) return False self.storage['dynamic'] = { 'http_code': { 'chart': 'squid_detailed_response_codes', 'func_dim_id': None, 'func_dim': None }, 'hier_code': { 'chart': 'squid_hier_code', 'func_dim_id': None, 'func_dim': lambda v: v.replace('HIER_', '') }, 'method': { 'chart': 'squid_method', 'func_dim_id': None, 'func_dim': None }, 'mime_type': { 'chart': 'squid_mime_type', 'func_dim_id': lambda v: str.lower(v) if str.lower(v) in MIME_TYPES else 'unknown', 'func_dim': None } } if not self.configuration.get('all_time', True): self.order.remove('squid_clients_all') return True
def check(self): if not self.log_path: self.error('log path is not specified') return False if not (self._find_recent_log_file() and os.access(self.log_path, os.R_OK)): self.error('{log_file} not readable or not exist'.format( log_file=self.log_path)) return False if not os.path.getsize(self.log_path): self.error('{log_file} is empty'.format(log_file=self.log_path)) return False last_line = read_last_line(self.log_path) if not last_line: return False return True
def get_data(self): data = dict() for disk in self.disks: if not disk.status: continue try: last_line = read_last_line(disk.path) except OSError: disk.status = False continue result = self.regex.findall(last_line) if not result: continue for a, n, r in result: data.update({'_'.join([disk.name, a]): r if self.raw_values else n}) return data or None
def get_data(self): data = dict() for disk in self.disks: if not disk.status: continue try: last_line = read_last_line(disk.path) except OSError: disk.status = False continue result = self.regex.findall(last_line) if not result: continue for a, n, r in result: data.update( {'_'.join([disk.name, a]): r if self.raw_values else n}) return data or None
def check(self): last_line = read_last_line(self.log_path) if not last_line: return False # Custom_log_format or predefined log format. if self.configuration.get('custom_log_format'): match_dict, error = self.find_regex_custom(last_line) else: match_dict, error = self.find_regex(last_line) # "match_dict" is None if there are any problems if match_dict is None: self.error(error) return False self.storage['unique_all_time'] = list() self.storage['url_pattern'] = check_patterns('url_pattern', self.configuration.get('categories')) self.storage['user_pattern'] = check_patterns('user_pattern', self.configuration.get('user_defined')) self.create_web_charts(match_dict) # Create charts self.info('Collected data: %s' % list(match_dict.keys())) return True
def read(self): self.size = os.path.getsize(self.path) return read_last_line(self.path)
def get_attributes(self): last_line = read_last_line(self.log_file.path) self.attributes = dict( (attr, SmartAttribute(attr, normalized, raw)) for attr, normalized, raw in REGEX.findall(last_line)) return True
def get_attributes(self): last_line = read_last_line(self.log_file.path) self.attributes = dict((attr, SmartAttribute(attr, normalized, raw)) for attr, normalized, raw in REGEX.findall(last_line)) return True