diff --git a/plugins/in_tail/tail.c b/plugins/in_tail/tail.c index 40373f5c184..a75c32a3c45 100644 --- a/plugins/in_tail/tail.c +++ b/plugins/in_tail/tail.c @@ -576,6 +576,11 @@ static struct flb_config_map config_map[] = { "Set one or multiple shell patterns separated by commas to exclude " "files matching a certain criteria, e.g: 'exclude_path *.gz,*.zip'" }, + { + FLB_CONFIG_MAP_BOOL, "ignore_unavailable", "false", + 0, FLB_TRUE, offsetof(struct flb_tail_config, ignore_unavailable), + "Do not search directories that do not exist for files." + }, { FLB_CONFIG_MAP_STR, "key", "log", 0, FLB_TRUE, offsetof(struct flb_tail_config, key), diff --git a/plugins/in_tail/tail_config.h b/plugins/in_tail/tail_config.h index d39249b93ee..ca13cfebd14 100644 --- a/plugins/in_tail/tail_config.h +++ b/plugins/in_tail/tail_config.h @@ -88,6 +88,7 @@ struct flb_tail_config { long refresh_interval_nsec;/* nanoseconds to re-scan */ int read_newly_discovered_files_from_head; /* read new files from head after startup */ int read_from_head; /* read new files from head */ + int ignore_unavailable; /* ignore unavailable paths during scanning */ int rotate_wait; /* sec to wait on rotated files */ int watcher_interval; /* watcher interval */ int ignore_older; /* ignore fields older than X seconds */ diff --git a/plugins/in_tail/tail_scan.c b/plugins/in_tail/tail_scan.c index 82dcda4bffa..e2109da19b9 100644 --- a/plugins/in_tail/tail_scan.c +++ b/plugins/in_tail/tail_scan.c @@ -110,13 +110,13 @@ int flb_tail_scan(struct mk_list *path_list, struct flb_tail_config *ctx) mk_list_foreach(head, path_list) { pattern = mk_list_entry(head, struct flb_slist_entry, _head); ret = tail_scan_path(pattern->str, ctx); - if (ret == -1) { - flb_plg_warn(ctx->ins, "error scanning path: %s", pattern->str); - } - else { + if (ret != -1) { flb_plg_debug(ctx->ins, "%i new files found on path '%s'", ret, pattern->str); } + else if (!ctx->ignore_unavailable) { + flb_plg_warn(ctx->ins, "error scanning path: %s", pattern->str); + } } return 0; diff --git a/plugins/in_tail/tail_scan_glob.c b/plugins/in_tail/tail_scan_glob.c index 25173c2c14a..b0b64802e47 100644 --- a/plugins/in_tail/tail_scan_glob.c +++ b/plugins/in_tail/tail_scan_glob.c @@ -183,7 +183,6 @@ static inline int do_glob(const char *pattern, int flags, return ret; } - /* Scan a path, register the entries and return how many */ static int tail_scan_path(const char *path, struct flb_tail_config *ctx) { @@ -212,12 +211,27 @@ static int tail_scan_path(const char *path, struct flb_tail_config *ctx) flb_plg_error(ctx->ins, "no memory space available"); return -1; case GLOB_ABORTED: - flb_plg_error(ctx->ins, "read error, check permissions: %s", path); + if (errno == EACCES) { + flb_plg_error(ctx->ins, "No read access for path: %s", path); + } else if (errno == ENOENT || errno == ENOTDIR) { + if (!ctx->ignore_unavailable) { + flb_plg_error(ctx->ins, "%s at path: %s", + (errno == ENOENT) ? "No such file" : "Not a directory", + path); + } + } else { + flb_plg_error(ctx->ins, "Unable to scan path (system error: %s): %s", + strerror(errno), path); + } return -1; case GLOB_NOMATCH: ret = stat(path, &st); if (ret == -1) { - flb_plg_debug(ctx->ins, "cannot read info from: %s", path); + if (errno == ENOTDIR && !ctx->ignore_unavailable) { + flb_plg_error(ctx->ins, "Not a directory at path: %s", path); + } else { + flb_plg_debug(ctx->ins, "cannot read info from: %s", path); + } } else { ret = access(path, R_OK);