diff --git a/include/fluent-bit/flb_custom.h b/include/fluent-bit/flb_custom.h index 4d63d3059c5..6c5f10726a2 100644 --- a/include/fluent-bit/flb_custom.h +++ b/include/fluent-bit/flb_custom.h @@ -27,6 +27,10 @@ #include #endif +/* Custom plugin flag masks */ +#define FLB_CUSTOM_NET_UPSTREAM 1 /* custom may use upstream net.* properties */ +#define FLB_CUSTOM_NET_DOWNSTREAM 2 /* custom may use downstream net.* properties */ + struct flb_custom_instance; struct flb_custom_plugin { @@ -57,7 +61,9 @@ struct flb_custom_instance { void *data; struct flb_custom_plugin *p; /* original plugin */ struct mk_list properties; /* config properties */ + struct mk_list net_properties; /* net properties */ struct mk_list *config_map; /* configuration map */ + struct mk_list *net_config_map;/* net configuration map */ struct mk_list _head; /* link to config->customs */ /* diff --git a/src/flb_custom.c b/src/flb_custom.c index 33f42c28e0d..ab606f667d3 100644 --- a/src/flb_custom.c +++ b/src/flb_custom.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include static inline int instance_id(struct flb_config *config) @@ -79,6 +81,16 @@ int flb_custom_set_property(struct flb_custom_instance *ins, } ins->log_level = ret; } + else if (strncasecmp("net.", k, 4) == 0 && tmp) { + kv = flb_kv_item_create(&ins->net_properties, (char *) k, NULL); + if (!kv) { + if (tmp) { + flb_sds_destroy(tmp); + } + return -1; + } + kv->val = tmp; + } else { /* * Create the property, we don't pass the value since we will @@ -178,6 +190,7 @@ struct flb_custom_instance *flb_custom_new(struct flb_config *config, instance->log_level = -1; mk_list_init(&instance->properties); + mk_list_init(&instance->net_properties); mk_list_add(&instance->_head, &config->customs); return instance; @@ -213,6 +226,28 @@ int flb_custom_plugin_property_check(struct flb_custom_instance *ins, } ins->config_map = config_map; + if ((p->flags & FLB_CUSTOM_NET_UPSTREAM) && (p->flags & FLB_CUSTOM_NET_UPSTREAM)) { + flb_error("[custom] cannot configure upstream and downstream " + "in the same custom plugin: '%s'", + p->name); + } + if (p->flags & FLB_CUSTOM_NET_UPSTREAM) { + ins->net_config_map = flb_upstream_get_config_map(config); + if (ins->net_config_map == NULL) { + flb_error("[custom] unable to load upstream properties: '%s'", + p->name); + return -1; + } + } + else if (p->flags & FLB_CUSTOM_NET_UPSTREAM) { + ins->net_config_map = flb_downstream_get_config_map(config); + if (ins->net_config_map == NULL) { + flb_error("[custom] unable to load downstream properties: '%s'", + p->name); + return -1; + } + } + /* Validate incoming properties against config map */ ret = flb_config_map_properties_check(ins->p->name, &ins->properties, ins->config_map); @@ -293,6 +328,7 @@ void flb_custom_instance_destroy(struct flb_custom_instance *ins) /* release properties */ flb_kv_release(&ins->properties); + flb_kv_release(&ins->net_properties); if (ins->alias) { flb_sds_destroy(ins->alias);