2727#include <fluent-bit/flb_pack.h>
2828#include <fluent-bit/flb_sds.h>
2929#include <fluent-bit/flb_time.h>
30+ #include <fluent-bit/flb_env.h>
3031#include <fluent-bit/flb_log_event_decoder.h>
3132#include <fluent-bit/flb_log_event_encoder.h>
33+
3234#include <msgpack.h>
3335
3436#include "fluent-bit/flb_mem.h"
@@ -76,6 +78,31 @@ static int cb_lua_pre_run(struct flb_filter_instance *f_ins,
7678 return ret ;
7779}
7880
81+ static int env_variables (struct flb_config * config , struct flb_luajit * lj )
82+ {
83+ struct mk_list * list ;
84+ struct mk_list * head ;
85+ struct flb_env * env ;
86+ struct flb_hash_table_entry * entry ;
87+
88+ lua_newtable (lj -> state );
89+
90+ env = (struct flb_env * ) config -> env ;
91+ list = (struct mk_list * ) & env -> ht -> entries ;
92+ mk_list_foreach (head , list ) {
93+ entry = mk_list_entry (head , struct flb_hash_table_entry , _head_parent );
94+ if (entry -> val_size <= 0 ) {
95+ continue ;
96+ }
97+ lua_pushlstring (lj -> state , entry -> key , entry -> key_len );
98+ lua_pushlstring (lj -> state , entry -> val , entry -> val_size );
99+ lua_settable (lj -> state , -3 );
100+ }
101+
102+ lua_setglobal (lj -> state , "FLB_ENV" );
103+ return 0 ;
104+ }
105+
79106static int cb_lua_init (struct flb_filter_instance * f_ins ,
80107 struct flb_config * config ,
81108 void * data )
@@ -101,6 +128,9 @@ static int cb_lua_init(struct flb_filter_instance *f_ins,
101128 }
102129 ctx -> lua = lj ;
103130
131+ /* register environment variables */
132+ env_variables (config , lj );
133+
104134 if (ctx -> enable_flb_null ) {
105135 flb_lua_enable_flb_null (lj -> state );
106136 }
0 commit comments