Skip to content

Commit 07db988

Browse files
committed
filters: lua: add example to access configuration variables.
Signed-off-by: lecaros <[email protected]>
1 parent b66c64e commit 07db988

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

pipeline/filters/lua.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,53 @@ The output of this process shows the conversion of the `datetime` of two timezon
572572
...
573573
```
574574

575+
### Using configuration variables
576+
577+
Fluent Bit supports definition of configuration variables, which can be done in the following way:
578+
579+
```yaml
580+
env:
581+
myvar1: myvalue1
582+
```
583+
584+
These variables can be accessed from the Lua code by referring to the FLB_ENV Lua table.
585+
Being this a Lua table, the subrecords can be accessed following the same syntax, i.e. `FLB_ENV['A']`.
586+
587+
#### Configuration
588+
589+
```yaml
590+
env:
591+
A: aaa
592+
B: bbb
593+
C: ccc
594+
595+
service:
596+
flush: 1
597+
log_level: info
598+
599+
pipeline:
600+
inputs:
601+
- name: random
602+
tag: test
603+
samples: 10
604+
605+
filters:
606+
- name: lua
607+
match: "*"
608+
call: append_tag
609+
code: |
610+
function append_tag(tag, timestamp, record)
611+
new_record = record
612+
new_record["my_env"] = FLB_ENV
613+
return 1, timestamp, new_record
614+
end
615+
616+
outputs:
617+
- name: stdout
618+
match: "*"
619+
```
620+
621+
#### Output
622+
623+
test: [[1731990257.781970977, {}], {"my_env"=>{"A"=>"aaa", "C"=>"ccc", "HOSTNAME"=>"monox-2.lan", "B"=>"bbb"}, "rand_value"=>4805047635809401856}]
624+

0 commit comments

Comments
 (0)