def _exclude_logs(self): """ Iterate through log file stores and remove ones that match exclude rules. """ # Take comma-separated string of pathname patterns and separate them into individual patterns exclude_rules = context.app_config.get('nginx', {}).get('exclude_logs', '').split(',') for rule in [x for x in exclude_rules if x]: # skip potentially empty rules due to improper formatting # access logs for excluded_file in glib(self.access_logs.keys(), rule): del self.access_logs[excluded_file] # error logs for excluded_file in glib(self.error_logs.keys(), rule): del self.error_logs[excluded_file]
def test_overall(self): excludes = [ 'access-frontend-*.log', 'receiver1-*.log', 'frontend2.log', '/var/log/nginx/frontend/*', '/var/log/naas/' ] file_paths = [ '/var/log/nginx/frontend/asdf.log', # exclude 4 '/var/log/nginx/frontend/frontend3.log', # exclude 4 '/var/log/blank.log', '/var/log/frontend2.log', # exclude 3 '/var/receiver1-2012.log', # exclude 2 '/var/log/naas/blah.log', # exclude 5 'access-frontend-asf.log' # exclude 1 ] results = file_paths for exclude_pathname in excludes: for match in glib.glib(file_paths, exclude_pathname): results.remove(match) assert_that(results, has_length(1)) assert_that(results[0], equal_to('/var/log/blank.log'))
def test_more(self): pattern = '/etc/nginx/*.conf' file_paths = [ '/etc/nginx/nginx.conf', '/etc/nginx/bir/aaa/subdir/host.conf', '/etc/nginx/conf.d/blockips.conf', '/etc/nginx/conf.d/default.conf', '/etc/nginx/conf.d/default.conf.bak', '/etc/nginx/conf.d/host.conf', '/etc/nginx/conf.d/proxy.conf', '/etc/nginx/conf.d/ssl.conf', '/etc/nginx/conf.d/servers/bamboo_server.conf', '/etc/nginx/conf.d/servers/dev1_server.conf', '/etc/nginx/conf.d/servers/dev1db00_server.conf', '/etc/nginx/conf.d/servers/docker_build_server.conf', '/etc/nginx/conf.d/servers/docker_registry_server.conf', '/etc/nginx/conf.d/servers/eurotax_proxy.conf', '/etc/nginx/conf.d/servers/int01_server.conf', '/etc/nginx/conf.d/servers/int01db00_server.conf', '/etc/nginx/conf.d/servers/nexus_server.conf', '/etc/nginx/conf.d/servers/soft2run_server.conf', '/etc/nginx/conf.d/servers/spearhead_server.conf', '/etc/nginx/conf.d/servers/toolsdb_server.conf', '/etc/nginx/conf.d/servers/webcache_server.conf.bak', '/etc/nginx/conf.d/servers/webcache_server_working.conf', '/etc/nginx/conf.d/tcp_streams/iboxdb_server.conf', '/etc/nginx/ssl/soft2run_ssl_cert.conf', '/etc/nginx/ssl/sph_ssl_cert.conf' ] results = glib.glib(file_paths, pattern) assert_that(results, has_length(1)) assert_that(results[0], equal_to('/etc/nginx/nginx.conf'))