我知道ntopng可以直接放到elasticsearch,但我的老板希望使用logtash作为层来将日志传输到elasticsearch。
我试了很多次,但都失败了。
ntopng日志如下:
{"index": {"_type": "ntopng", "_index": "ntopng-2016.08.23"}}
{ "@timestamp": "2016-08-23T01:49:41.0Z", "type": "ntopng", "IN_SRC_MAC": "04:2A:E2:0D:62:FB", "OUT_DST_MAC": "00:16:3E:8D:B7:E4", "IPV4_SRC_ADDR": "14.152.84.14", "IPV4_DST_ADDR": "xxx.xxx.xxx", "L4_SRC_PORT": 34599, "L4_DST_PORT": 53, "PROTOCOL": 17, "L7_PROTO": 5, "L7_PROTO_NAME": "DNS", "IN_PKTS": 15, "IN_BYTES": 1185, "OUT_PKTS": 15, "OUT_BYTES": 22710, "FIRST_SWITCHED": 1471916981, "LAST_SWITCHED": 1471916981, "SRC_IP_COUNTRY": "CN", "SRC_IP_LOCATION": [ 113.250000, 23.116699 ], "DST_IP_COUNTRY": "VN", "DST_IP_LOCATION": [ 105.849998, 21.033300 ], "NTOPNG_INSTANCE_NAME": "ubuntu", "INTERFACE": "ens192", "DNS_QUERY": "cpsc.gov", "PASS_VERDICT": true }Logstash配置:
input {
tcp {
port => 5000
codec => json
}
}
filter{
json{
source => "message"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
stdout{ codec => rubydebug }
}谢谢
发布于 2016-08-23 11:54:33
因为ntopng日志已经是Elasticsearch期望的批量格式,所以不需要使用elasticsearch输出,但是可以直接使用http输出,如下所示。不需要让Logstash解析JSON,只需将原始批量命令转发到ES即可。
但是有一个问题:我们需要在第二行之后添加一个换行符,否则ES将拒绝批量调用。我们可以通过在message后面添加一个逐字换行符的mutate/update过滤器来实现这一点。试一试,这将会起作用。
input {
tcp {
port => 5000
codec => multiline {
pattern => "_index"
what => "next"
}
}
}
filter{
mutate {
update => {"message" => "%{message}
"}
}
}
output {
http {
http_method => "post"
url => "http://localhost:9200/_bulk"
format => "message"
message => "%{message}"
}
}https://stackoverflow.com/questions/39091750
复制相似问题