愚者求师之过,智者从师之长。

logstash 接收 http 数据

Logstash | 作者 juin | 发布于2018年10月15日 | 阅读数:7036

请教大家一个问题:
把数据通过http post 请求发送给logstash,logstash 收到的是一个特殊的字符串
特殊指之处在于发送方的数据其实是个json,但是发送的时候加了双引号按string 类型发的
我这边不能修改发送方的数据,只能在接收时作处理
想问下这种情况怎么去解析这个字符串
 
发送的数据如
"[{"headers":{ "_enc":1},"body":"2018-10-12 11:38:49\t5080002\tcsfd"}]"
已邀请:

rochy - rochy_he

赞同来自: juin

split => { "message" => "\n" }
你上面配置写错了

rochy - rochy_he

赞同来自:

使用 gork filter ,配置正则表达式匹配真正的 json 内容即可

juin - 大数据开发

赞同来自:

 
input {
http {
host => "10.17.64.126"
port => 12366
codec => "plain"
additional_codecs => {"text/plain"=>"plain"}
threads => 4
ssl => false
}
}

filter {
mutate {
split => ["message", "\t"]
add_field => {
"ftimeold" => "%{[message][0]}"
}
add_field => {
"serverold" => "%{[message][1]}"
}
add_field => {
"logname" => "%{[message][2]}"
}
add_field => {
"title" => "%{[message][3]}"
}
add_field => {
"info_version" => "%{[message][4]}"
}
add_field => {
"uid" => "%{[message][5]}"
}
add_field => {
"role_id" => "%{[message][6]}"
}
add_field => {
"batid" => "%{[message][7]}"
}
}
}

output {
stdout{codec => json}
}

要回复问题请先登录注册