From e5251a8a187a3f5697165fe2957d7ab63caf1da0 Mon Sep 17 00:00:00 2001 From: Phillip Whelan Date: Mon, 21 Aug 2023 22:15:43 -0400 Subject: [PATCH] custom_calyptia: if/else style fixes. Signed-off-by: Phillip Whelan --- plugins/custom_calyptia/calyptia.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/custom_calyptia/calyptia.c b/plugins/custom_calyptia/calyptia.c index 2edf6fbca30..8a905b4fe1c 100644 --- a/plugins/custom_calyptia/calyptia.c +++ b/plugins/custom_calyptia/calyptia.c @@ -169,6 +169,7 @@ flb_sds_t custom_calyptia_pipeline_config_get(struct flb_config *ctx) o_ins = mk_list_entry(head, struct flb_output_instance, _head); flb_sds_printf(&buf, "[OUTPUT]\n"); flb_sds_printf(&buf, " name %s\n", o_ins->name); + if (o_ins->match) { flb_sds_printf(&buf, " match %s\n", o_ins->match); } @@ -242,6 +243,7 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, /* direct connect / routing */ ret = flb_router_connect_direct(ctx->i, cloud); + if (ret != 0) { flb_plg_error(ctx->ins, "could not load Calyptia Cloud connector"); flb_free(ctx); @@ -254,7 +256,8 @@ static struct flb_output_instance *setup_cloud_output(struct flb_config *config, k = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head); v = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head); kv = flb_sds_create_size(strlen(k->str) + strlen(v->str) + 1); - if(!kv) { + + if (!kv) { flb_free(ctx); return NULL; } @@ -330,10 +333,12 @@ static flb_sds_t sha256_to_hex(unsigned char *sha256) for (i = 0; i < 32; i++) { tmp = flb_sds_printf(&hex, "%02x", sha256[i]); + if (!tmp) { flb_sds_destroy(hex); return NULL; } + hex = tmp; } @@ -350,6 +355,7 @@ static flb_sds_t get_machine_id(struct calyptia *ctx) /* retrieve raw machine id */ ret = flb_utils_get_machine_id(&buf, &s); + if (ret == -1) { flb_plg_error(ctx->ins, "could not obtain machine id"); return NULL; @@ -399,6 +405,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, if (!ctx->machine_id) { /* machine id */ ctx->machine_id = get_machine_id(ctx); + if (ctx->machine_id == NULL) { flb_plg_error(ctx->ins, "unable to retrieve machine_id"); return -1; @@ -407,10 +414,12 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, /* input collector */ ctx->i = flb_input_new(config, "fluentbit_metrics", NULL, FLB_TRUE); + if (!ctx->i) { flb_plg_error(ctx->ins, "could not load metrics collector"); return -1; } + flb_input_set_property(ctx->i, "tag", "_calyptia_cloud"); flb_input_set_property(ctx->i, "scrape_on_start", "true"); flb_input_set_property(ctx->i, "scrape_interval", "30"); @@ -418,6 +427,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, /* output cloud connector */ if (ctx->fleet_id != NULL) { ctx->o = setup_cloud_output(config, ctx); + if (ctx->o == NULL) { return -1; } @@ -425,6 +435,7 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, if (ctx->fleet_id || ctx->fleet_name) { ctx->fleet = flb_input_new(config, "calyptia_fleet", NULL, FLB_FALSE); + if (!ctx->fleet) { flb_plg_error(ctx->ins, "could not load Calyptia Fleet plugin"); return -1; @@ -434,7 +445,8 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, // TODO: set this once the fleet_id has been retrieved... // flb_output_set_property(ctx->o, "fleet_id", ctx->fleet_id); flb_input_set_property(ctx->fleet, "fleet_name", ctx->fleet_name); - } else { + } + else { flb_output_set_property(ctx->o, "fleet_id", ctx->fleet_id); flb_input_set_property(ctx->fleet, "fleet_id", ctx->fleet_id); } @@ -442,19 +454,25 @@ static int cb_calyptia_init(struct flb_custom_instance *ins, flb_input_set_property(ctx->fleet, "api_key", ctx->api_key); flb_input_set_property(ctx->fleet, "host", ctx->cloud_host); flb_input_set_property(ctx->fleet, "port", ctx->cloud_port); + if (ctx->cloud_tls == 1) { flb_input_set_property(ctx->fleet, "tls", "on"); - } else { + } + else { flb_input_set_property(ctx->fleet, "tls", "off"); } + if (ctx->cloud_tls_verify == 1) { flb_input_set_property(ctx->fleet, "tls.verify", "on"); - } else { + } + else { flb_input_set_property(ctx->fleet, "tls.verify", "off"); } + if (ctx->fleet_config_dir) { flb_input_set_property(ctx->fleet, "config_dir", ctx->fleet_config_dir); } + if (ctx->machine_id) { flb_input_set_property(ctx->fleet, "machine_id", ctx->machine_id); }