Skip to content

Commit 0c4f3f0

Browse files
niedbalskiedsiper
authored andcommitted
out_custom_calyptia: enable machine_id config property.
if machine_id is set, that string value will be used when registering the agent, if not given, a locally generated one will be used. Signed-off-by: Jorge Niedbalski <j@calyptia.com>
1 parent c785952 commit 0c4f3f0

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

plugins/custom_calyptia/calyptia.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct calyptia {
3535
flb_sds_t store_path;
3636
flb_sds_t cloud_host;
3737
flb_sds_t cloud_port;
38+
flb_sds_t machine_id;
39+
3840
int cloud_tls;
3941
int cloud_tls_verify;
4042

@@ -258,7 +260,6 @@ static int cb_calyptia_init(struct flb_custom_instance *ins,
258260
flb_config_map_foreach(head, mv, ctx->add_labels) {
259261
k = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
260262
v = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
261-
262263
kv = flb_sds_create_size(strlen(k->str) + strlen(v->str) + 1);
263264
if(!kv) {
264265
flb_free(ctx);
@@ -277,6 +278,10 @@ static int cb_calyptia_init(struct flb_custom_instance *ins,
277278
flb_output_set_property(ctx->o, "store_path", ctx->store_path);
278279
}
279280

281+
if (ctx->machine_id) {
282+
flb_output_set_property(ctx->o, "machine_id", ctx->machine_id);
283+
}
284+
280285
/* Override network details: development purposes only */
281286
if (ctx->cloud_host) {
282287
flb_output_set_property(ctx->o, "cloud_host", ctx->cloud_host);
@@ -359,6 +364,11 @@ static struct flb_config_map config_map[] = {
359364
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct calyptia, add_labels),
360365
"Label to append to the generated metric."
361366
},
367+
{
368+
FLB_CONFIG_MAP_STR, "machine_id", NULL,
369+
0, FLB_TRUE, offsetof(struct calyptia, machine_id),
370+
"Custom machine_id to be used when registering agent"
371+
},
362372

363373
/* EOF */
364374
{0}

plugins/out_calyptia/calyptia.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,16 @@ static struct flb_calyptia *config_init(struct flb_output_instance *ins,
657657
}
658658
}
659659

660-
/* machine id */
661-
ret = get_machine_id(ctx, &machine_id, &size);
662-
if (ret == -1) {
663-
return NULL;
660+
/* If no machine_id has been provided via a configuration option get it from the local machine-id. */
661+
if (!ctx->machine_id) {
662+
/* machine id */
663+
ret = get_machine_id(ctx, &machine_id, &size);
664+
if (ret == -1) {
665+
return NULL;
666+
}
667+
ctx->machine_id = (flb_sds_t) machine_id;
664668
}
665-
ctx->machine_id = (flb_sds_t) machine_id;
669+
666670
flb_plg_debug(ctx->ins, "machine_id=%s", ctx->machine_id);
667671

668672
/* Upstream */
@@ -872,6 +876,11 @@ static struct flb_config_map config_map[] = {
872876
0, FLB_TRUE, offsetof(struct flb_calyptia, api_key),
873877
"Calyptia Cloud API Key."
874878
},
879+
{
880+
FLB_CONFIG_MAP_STR, "machine_id", NULL,
881+
0, FLB_TRUE, offsetof(struct flb_calyptia, machine_id),
882+
"Custom machine_id to be used when registering agent"
883+
},
875884

876885
{
877886
FLB_CONFIG_MAP_STR, "store_path", NULL,

0 commit comments

Comments
 (0)