diff --git a/plugins/out_file/file.c b/plugins/out_file/file.c index 2e47c9666..95d28e438 100644 --- a/plugins/out_file/file.c +++ b/plugins/out_file/file.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,7 @@ struct flb_file_conf { int csv_column_names; int mkdir; struct flb_output_instance *ins; + char hostname[256]; }; static char *check_delimiter(const char *str) @@ -141,6 +143,9 @@ static int cb_file_init(struct flb_output_instance *ins, } } + if (gethostname(ctx->hostname, sizeof(ctx->hostname)) != 0) + snprintf(ctx->hostname, sizeof(ctx->hostname), "%s", "localhost"); + tmp = flb_output_get_property("delimiter", ins); ret_str = check_delimiter(tmp); if (ret_str != NULL) { @@ -233,12 +238,8 @@ static int template_output_write(struct flb_file_conf *ctx, int i; msgpack_object_kv *kv; - /* - * Right now we treat "{time}" specially and fill the placeholder - * with the metadata timestamp (formatted as float). - */ - if (!strncmp(key, "time", size)) { - fprintf(fp, "%f", flb_time_to_double(tm)); + if (!strncmp(key, "hostname", size)) { + fprintf(fp, "%s", ctx->hostname); return 0; }