我的lua脚本正在返回记录[键']
我正在尝试使用Lua使用Fluent Pit来更改日志来吹捧/掩模日志。该过滤器包含一个简单的数字替换为#使用GSUB。我正在以JSON格式的lua输入日志,无法访问钥匙值。
test.lua
function modifyRecord(tag, timestamp, record)
local new_record = record
old_message = record["message"]
digits = "[%d]+"
new_message = old_message:gsub(digits, "#")
new_record["message"] = new_message
return 1, timestamp, new_record
end
日志文件 - test.log
echo '{"Test": "Logs","message":"This is a message 123432"}' >> test.log
fluent-bit.conf
[SERVICE]
# This is the main configuration block for fluent bit.
# Ensure the follow line exists somewhere in the SERVICE block
Plugins_File plugins.conf
[INPUT]
Name tail
#Path /export/home/dummy/newrelic-infra/var/log/newrelic-infra/newrelic-infra.log
Path /export/home/dummy/nrfb/test.log
[OUTPUT]
Name newrelic
Match *
licenseKey <key>
proxy <proxy>
endpoint <endpoint>
[FILTER]
Name modify
Match *
Add hostname <hostname>
Add service_name newrelic-infra-fluent-bit
[FILTER]
Name lua
Match *
script /export/home/dummy/nrfb/test.lua
call modifyRecord
fluent> flueent-bit logs
-bash-4.2$ ./fluent-bit -c ./fluent-bit.conf
Fluent Bit v1.6.3
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io
[2022/04/15 11:09:20] [ info] [engine] started (pid=11454)
[2022/04/15 11:09:20] [ info] [storage] version=1.0.6, initializing...
[2022/04/15 11:09:20] [ info] [storage] in-memory
[2022/04/15 11:09:20] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
[2022/04/15 11:09:20] [ info] [sp] stream processor started
[2022/04/15 11:09:20] [ info] [input:tail:tail.0] inotify_fs_add(): inode=194 watch_fd=1 name=/export/home/dummy/nrfb/test.log
[2022/04/15 11:09:49] [error] [filter:lua:lua.1] error code 2: /export/home/dummy/nrfb/test.lua:5: attempt to index global 'old_message' (a nil value)
I am trying to fliter/mask logs by using fluent bit to change logs using lua. The filter contains a simple substitution of digits to # using gsub. I am entering logs in JSON format bit lua is not able to access key value.
test.lua
function modifyRecord(tag, timestamp, record)
local new_record = record
old_message = record["message"]
digits = "[%d]+"
new_message = old_message:gsub(digits, "#")
new_record["message"] = new_message
return 1, timestamp, new_record
end
Log file – test.log
echo '{"Test": "Logs","message":"This is a message 123432"}' >> test.log
fluent-bit.conf
[SERVICE]
# This is the main configuration block for fluent bit.
# Ensure the follow line exists somewhere in the SERVICE block
Plugins_File plugins.conf
[INPUT]
Name tail
#Path /export/home/dummy/newrelic-infra/var/log/newrelic-infra/newrelic-infra.log
Path /export/home/dummy/nrfb/test.log
[OUTPUT]
Name newrelic
Match *
licenseKey <key>
proxy <proxy>
endpoint <endpoint>
[FILTER]
Name modify
Match *
Add hostname <hostname>
Add service_name newrelic-infra-fluent-bit
[FILTER]
Name lua
Match *
script /export/home/dummy/nrfb/test.lua
call modifyRecord
Fluent-bit logs
-bash-4.2$ ./fluent-bit -c ./fluent-bit.conf
Fluent Bit v1.6.3
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io
[2022/04/15 11:09:20] [ info] [engine] started (pid=11454)
[2022/04/15 11:09:20] [ info] [storage] version=1.0.6, initializing...
[2022/04/15 11:09:20] [ info] [storage] in-memory
[2022/04/15 11:09:20] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
[2022/04/15 11:09:20] [ info] [sp] stream processor started
[2022/04/15 11:09:20] [ info] [input:tail:tail.0] inotify_fs_add(): inode=194 watch_fd=1 name=/export/home/dummy/nrfb/test.log
[2022/04/15 11:09:49] [error] [filter:lua:lua.1] error code 2: /export/home/dummy/nrfb/test.lua:5: attempt to index global 'old_message' (a nil value)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在配置文件中遇到了错误,
它应该设置为JSON的解析器设置/解析。
输入和添加解析器的变化可以解决问题。
I had mistake in config file
It should have parser set to look/parse for json.
Changes in input and addition of parser did the trick.