diff --git a/plugins/in_calyptia_fleet/in_calyptia_fleet.c b/plugins/in_calyptia_fleet/in_calyptia_fleet.c index b7352f7a8e1..0a4100de8e0 100644 --- a/plugins/in_calyptia_fleet/in_calyptia_fleet.c +++ b/plugins/in_calyptia_fleet/in_calyptia_fleet.c @@ -605,6 +605,7 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, flb_sds_t cfgoldname; flb_sds_t cfgcurname; flb_sds_t header; + flb_sds_t hdr; FILE *cfgfp; const char *fbit_last_modified; int fbit_last_modified_len; @@ -691,16 +692,16 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, } header = flb_sds_create_size(4096); if (ctx->fleet_name == NULL) { - flb_sds_printf(&header, + hdr = flb_sds_printf(&header, "[CUSTOM]\n" - " Name calyptia\n" - " api_key %s\n" - " fleet_id %s\n" - " add_label fleet_id %s\n" - " fleet.config_dir %s\n" - " calyptia_host %s\n" - " calyptia_port %d\n" - " calyptia_tls %s\n", + " Name calyptia\n" + " api_key %s\n" + " fleet_id %s\n" + " add_label fleet_id %s\n" + " fleet.config_dir %s\n" + " calyptia_host %s\n" + " calyptia_port %d\n" + " calyptia_tls %s\n", ctx->api_key, ctx->fleet_id, ctx->fleet_id, @@ -710,7 +711,7 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, tls_setting_string(ctx->ins->use_tls) ); } else { - flb_sds_printf(&header, + hdr = flb_sds_printf(&header, "[CUSTOM]\n" " Name calyptia\n" " api_key %s\n" @@ -731,6 +732,17 @@ static int in_calyptia_fleet_collect(struct flb_input_instance *ins, tls_setting_string(ctx->ins->use_tls) ); } + if (hdr == NULL) { + fclose(cfgfp); + goto http_error; + } + if (ctx->machine_id) { + hdr = flb_sds_printf(&header, " machine_id %s\n", ctx->machine_id); + if (hdr == NULL) { + fclose(cfgfp); + goto http_error; + } + } fwrite(header, strlen(header), 1, cfgfp); flb_sds_destroy(header); fwrite(data, client->resp.payload_size, 1, cfgfp);