我尝试使用heka(而不是logstash)作为日志解析器来插入elasticsearch。此时,我使用payloadregexdecoder分割每个字段。
除整数类型外,大多数配置都能正常工作。
输入日志字符串
May 4 13:01:04 db1 monitoring: 2015-05-04T13:01:01Z 174.35.6.22 aaaa bbbb 111
这是我的heka配置示例。
[fdb]
type = "PayloadRegexDecoder"
match_regex = '^(?P<month>.+?) (?P<day>.+?) (?P<time>.+?) (?P<remote_user>.+?) monitoring: (?P<Timestamp>.+?) (?P<ip>.+?) (?P<a>.+?) (?P<b>.+?) (?P<int_test>\d+)'
[fdb.message_fields]
Type = "f_monitoring"
month = "%month%"
day = "%day%"
time = "%time%"
remote_user = "%remote_user%"
ip|ipv4 = "%ip%"
a = "%a%"
b = "%b%"
int_test|B = "%int_test%"`
这是此设置的结果。
:Timestamp: 2015-05-04 13:01:01 +0000 UTC
:Type: f_monitoring
:Hostname:
:Pid: 0
:Uuid: b824d53c-7d7e-4424-a123-780aa37bf879
:Logger: UdpInput
:Payload: May 4 13:01:04 db1 monitoring: 2015-05-04T13:01:01Z 174.35.6.22 aaaa bbbb 111
:EnvVersion:
:Severity: 7
:Fields:
| name:"int_test" type:string value:"111" representation:"B"
| name:"a" type:string value:"aaaa"
| name:"time" type:string value:"13:01:04"
| name:"b" type:string value:"bbbb"
| name:"ip" type:string value:"174.35.6.22" representation:"ipv4"
| name:"day" type:string value:"4"
| name:"remote_user" type:string value:"db1"
| name:"month" type:string value:"May"
我想知道如何将int\u测试的类型从string改为integer或double。
1条答案
按热度按时间fsi0uk1n1#
据我所知,你不能。在源代码中,正则表达式匹配的值总是一个字符串。你可以改变表示法,但我不知道那会改变什么。
不过,您可以添加一个lua解码器。我认为你不能从消息中删除字段。因此,您必须将消息的副本拉入lua,转换字段,然后发回经过修改的消息。
下面是lua代码的概要(未测试):
如果您将lua文件命名为convertint.lua,下面是您将添加到配置中的内容;您还必须更新输入以使用“chain\u fbp”而不是“fbp”: