Created
May 28, 2015 11:19
-
-
Save VerosK/01818b5e43428a7db705 to your computer and use it in GitHub Desktop.
Logstash - parse JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter { | |
# if it looks like json, tag it | |
if [type] == 'syslog' and [message] =~ '{.*}' { | |
json { | |
source => 'message' | |
target => 'json_data' | |
add_tag => ['has_json'] | |
} | |
} | |
if "has_json" in [tags] { | |
mutate { | |
rename => [ | |
"[json_data][Message]", "message", | |
"[json_data][message]", "message" | |
] | |
} | |
mutate { # save @message to @message.raw (if needed) | |
rename => ['@message', '@message.raw'] | |
} | |
mutate { # save message to @message (if needed) | |
add_field => ['@message', '%{message}'] | |
} | |
grok { # if message contains date, drop the date | |
match => [ "message", "\[%{MONTHDAY}/%{MONTH}/%{YEAR} %{TIME}] +%{GREEDYDATA:message}" ] | |
overwrite => ['message'] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment