Skip to content

Instantly share code, notes, and snippets.

@fetep
Created December 31, 2011 06:54
Show Gist options
  • Save fetep/1543170 to your computer and use it in GitHub Desktop.
Save fetep/1543170 to your computer and use it in GitHub Desktop.
Logstash JSON filter
input {
file {
type => syslog
path => "/var/log/messages"
}
}
filter {
grok {
type => syslog
pattern => ["%{SYSLOGLINE}"]
named_captures_only => true
}
grep {
type => syslog
match => ["program", "jsontest"]
drop => false
add_tag => json
}
json {
type => syslog
tags => json
# parse JSON in "message" field,
# put resulting structure in "data" field
message => data
}
}
output {
stdout {
debug => true
}
}
{
"@source" => "file://carrera.databits.net//var/log/messages",
"@type" => "syslog",
"@tags" => [],
"@fields" => {
"timestamp" => [
[0] "Dec 31 00:53:11"
],
"timestamp8601" => [],
"facility" => [],
"priority" => [],
"logsource" => [
[0] "carrera"
],
"program" => [
[0] "test"
],
"pid" => [],
"message" => [
[0] "{\"level\": \"info\", \"message\": \"foo bar\"}"
]
},
"@timestamp" => "2011-12-31T06:53:12.816000Z",
"@source_host" => "carrera.databits.net",
"@source_path" => "//var/log/messages",
"@message" => "Dec 31 00:53:11 carrera test: {\"level\": \"info\", \"message\": \"foo bar\"}"
}
{
"@source" => "file://carrera.databits.net//var/log/messages",
"@type" => "syslog",
"@tags" => [
[0] "json"
],
"@fields" => {
"timestamp" => [
[0] "Dec 31 00:53:04"
],
"timestamp8601" => [],
"facility" => [],
"priority" => [],
"logsource" => [
[0] "carrera"
],
"program" => [
[0] "jsontest"
],
"pid" => [],
"message" => [
[0] "{\"level\": \"info\", \"message\": \"foo bar\"}"
],
"data" => {
"level" => "info",
"message" => "foo bar"
}
},
"@timestamp" => "2011-12-31T06:53:04.807000Z",
"@source_host" => "carrera.databits.net",
"@source_path" => "//var/log/messages",
"@message" => "Dec 31 00:53:04 carrera jsontest: {\"level\": \"info\", \"message\": \"foo bar\"}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment