Skip to content

Commit

Permalink
custom_calyptia: if/else style fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Whelan <[email protected]>
  • Loading branch information
pwhelan committed Aug 22, 2023
1 parent ca61fc5 commit e5251a8
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions plugins/custom_calyptia/calyptia.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -407,24 +414,28 @@ 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");

/* output cloud connector */
if (ctx->fleet_id != NULL) {
ctx->o = setup_cloud_output(config, ctx);

if (ctx->o == NULL) {
return -1;
}
}

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;
Expand All @@ -434,27 +445,34 @@ 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);
}

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);
}
Expand Down

0 comments on commit e5251a8

Please sign in to comment.