def get_error_summary(self, service_names): res = {} for service_name in service_names: client = docker.from_env() container = client.containers.get(service_name) res[service_name] = Errors(log_level='-', error_count=0) for line in container.logs().decode('utf-8').split('\n'): if service_name not in line: continue # Reset the counter for restart/start if 'Starting {}...'.format(service_name) in line: res[service_name].error_count = 0 elif 'ERROR' in line: res[service_name].error_count += 1 return res
def get_error_summary(self, service_names): """Get the list of services with the error count. Args: service_names: List of service names. Returns: A dictionary with service name as a key and the Errors object as a value. Raises: PermissionError: User has no permision to exectue the command """ configs = { service_name: load_service_mconfig_as_json(service_name) for service_name in service_names } res = { service_name: Errors( log_level=configs[service_name].get('logLevel', 'INFO'), error_count=0, ) for service_name in service_names } syslog_path = '/var/log/syslog' if not os.access(syslog_path, os.R_OK): raise PermissionError( 'syslog is not readable. ' 'Try `sudo chmod a+r {}`. ' 'Or execute the command with sudo ' 'permissions: `venvsudo`'.format(syslog_path), ) with open(syslog_path, 'r', encoding='utf-8') as f: for line in f: for service_name in service_names: if service_name not in line: continue # Reset the counter for restart/start if 'Starting {}...'.format(service_name) in line: res[service_name].error_count = 0 elif 'ERROR' in line: res[service_name].error_count += 1 return res
def get_error_summary(self, service_names): configs = {service_name: load_service_mconfig_as_json(service_name) for service_name in service_names} res = {service_name: Errors(log_level=configs[service_name]['logLevel'], error_count=0) for service_name in service_names} syslog_path = '/var/log/syslog' if not os.access(syslog_path, os.R_OK): raise PermissionError('syslog is not readable. ' 'Try `sudo chmod a+r {}`. ' 'Or execute the command with sudo ' 'permissions: `venvsudo`'.format(syslog_path)) with open(syslog_path, 'r') as f: for line in f: for service_name in service_names: if service_name not in line: continue # Reset the counter for restart/start if 'Starting {}...'.format(service_name) in line: res[service_name].error_count = 0 elif 'ERROR' in line: res[service_name].error_count += 1 return res