Jiri_Petak
(Jiri Petak)
September 25, 2018, 2:42pm
1
Hi, i would like to parse some fields from json logs from AWS WAF. On input logstash use:
s3 {
bucket => "XXXX"
access_key_id => "XXXX"
secret_access_key => "XXXX"
prefix => "waf/"
region => "XXX"
sincedb_path => "/tmp/s3.sincedb"
add_field => [ "lso_name", "NULL", "lsi_type", "s3", "lsi_name", "waf" ]
codec => "json"
}
I get messages like:
{
"httpSourceName"=>"CF",
"httpRequest"=> {
"clientIp"=>"XX.XX.XX.XX",
"httpMethod"=>"GET",
"requestId"=>"XXXX",
"uri"=>"XXX",
"headers"=>
[
{"name"=>"Host", "value"=>"test.exmaple.com "},
{"name"=>"user-agent", "value"=>"Mozilla/5.0"},
{"name"=>"accept", "value"=>"/ "}
]
}
}
I am trying to parse that header in logstash filter, but cant do it.
Output in kibana should be like:
"httpRequest.headers.Host" => "test.example.com "
"httpRequest.headers.user-agent" => "Mozilla/5.0"
I tryed json filter even kv, but with no success.
Thanks for any reply.
yaauie
(Ry Biesemeyer)
September 26, 2018, 12:23am
2
As it currently stands, your Elasticsearch index is getting a field httpRequest.headers.name
and another called httpRequest.headers.value
, which doesn't allow you to map names to values.
The array-of-objects will need to be transposed into a single object with named values.
I made something for you
pipeline.conf
filter {
ruby {
path => "${PWD}/transpose.logstash-filter-ruby.rb"
script_params => {
source => "[proplist]"
}
}
}
transpose.logstash-filter-ruby.rb
###############################################################################
# transpose.logstash-filter-ruby.rb
# ---------------------------------
# A script for a Ruby filter to transpose an array of two-element objects into
# a single map
###############################################################################
#
# Copyright 2018 Ry Biesemeyer
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
This file has been truncated. show original
With the above-linked transpose.logstash-filter-ruby.rb
, you could do the following:
filter {
ruby {
path => "/path/to/transpose.logstash-filter-ruby.rb"
script_params => {
"source" => "[httpRequest][headers]"
}
}
}
1 Like
Jiri_Petak
(Jiri Petak)
September 26, 2018, 9:09am
3
Thanks, thats awesome! Works like a charm
1 Like
system
(system)
Closed
October 24, 2018, 9:09am
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.