[英]Fluent D record_transformer plugin and Ruby for eventual use with elasticsearch,Kibana
I am currently using the fluentd record_transformer plugin to transform syslog messages. 我目前正在使用fluentd record_transformer插件来转换syslog消息。 I wanted to know how to implement this set of c++ commands in ruby to find a comma and get a substring up to that position and store it in a new field (Duration): 我想知道如何在ruby中实现这套c ++命令,以找到一个逗号并获取到该位置的子字符串并将其存储在新字段(持续时间)中:
std::string str="We think in generalities, but we live in details.";
std::size_t pos = str.find(',');
std::string newstring = str.substr (3,pos);
I have tried : 我努力了 :
<filter xyz.**>
@type record_transformer
enable_ruby true
<record>
Duration ${record["message"][32..(("message".index(/\,/,32)).to_i)]}
</record>
But have been unsuccessful. 但是一直没有成功。 I acknowledge this is a rather basic question, but all help will be greatly appreciated. 我承认这是一个相当基本的问题,但是所有帮助将不胜感激。
<source>
@type dummy
dummy {"message": "We think in generalities, but we live in details."}
tag dummy
@label @INPUT
</source>
<label @INPUT>
<filter>
@type record_transformer
enable_ruby true
<record>
duration ${record["message"].slice(/,([^,]{3})/, 1)}
</record>
</filter>
<match>
@type stdout
</match>
</label>
This will print like followings: 打印结果如下:
2018-09-12 19:29:08.029546388 +0900 dummy: {"message":"We think in generalities, but we live in details.","duration":" bu"}
2018-09-12 19:29:09.031650493 +0900 dummy: {"message":"We think in generalities, but we live in details.","duration":" bu"}
2018-09-12 19:29:10.033424279 +0900 dummy: {"message":"We think in generalities, but we live in details.","duration":" bu"}
If you want to parse syslog format lines, you can use https://docs.fluentd.org/v1.0/articles/parser_syslog instead of filter_record_transformer. 如果要解析syslog格式行,则可以使用https://docs.fluentd.org/v1.0/articles/parser_syslog代替filter_record_transformer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.