I'm trying to parse my message into json fields using Json filters but running into issues
Error:
Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [ \\t\\r\\n], \"#\", \"=>\" at line 17, column 14 (byte 387) after filter {\n if [type] == \"app-data\" {\n mutate {\n rename => [\"env\", \"Environment\" ]\n }\n filter {\n json ", :backtrace=>["/Users/metrics-poc/logstash-7.10.0/logstash-core/lib/logstash/compiler.rb:32:in compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:184:in initialize'", "org/logstash/execution/JavaBasePipelineExt.java:69:in initialize'", "/Users/metrics-poc/logstash-7.10.0/logstash-core/lib/logstash/java_pipeline.rb:47:in initialize'", "/Users/metrics-poc/logstash-7.10.0/logstash-core/lib/logstash/pipeline_action/create.rb:52:in execute'", "/Users/metrics-poc/logstash-7.10.0/logstash-core/lib/logstash/agent.rb:365:in block in converge_state'"]}
Input for Logstash:
timestamp:2020-11-30T02:41:41.244Z,message:{"ID":"1394","Type":"com.5","STAGE":"preview-0","ACCOUNT_NUMBER":"12345","REGION":"US-EAST-8"}
Logstash config file
input {
file {
path => "/Users/metrics-poc/filebeat-output.log"
add_field => {"env" => "prod"}
add_field => {"Hostname" => "ELB-1"}
start_position => "beginning"
type => "app-data"
}
}
filter {
if [type] == "app-data" {
mutate {
rename => ["env", "Environment" ]
}
filter {
json {
source => "message"
target => "jsoncontent" # with multiple layers structure
}
}
}
}
output {
stdout { codec => rubydebug }
}
I've tried using CSV and grok failures but I thought json filter is the ideal one to filter json data. here's an sample of output using csv filter:
{
"Hostname" => "ELB-1",
"Environment" => "prod",
"path" => "/Users/a664302/fidelity_projects/metrics-poc/filebeat-output.log",
"tags" => [
[0] "_csvparsefailure"
],
"@version" => "1",
"message" => "timestamp:2020-11-30T02:41:41.244Z,message:{\"ID\":\"1394\",\"Type\":\"com.5\",\"STAGE\":\"preview-0\",\"ACCOUNT_NUMBER\":\"12345\",\"REGION\":\"US-EAST-1\"}",
"@timestamp" => 2020-11-30T07:41:42.484Z,
"host" => "MACLB1781",
"type" => "app-data"
}
Ideally what i would like to have is to split the message into individual fields(timestamp as separate field and every json key-value pair in "message" as separate field. That's all I'm trying to do