Hi,
I have the following initial situation, we get various log messages which have JSON content, they look like this, for example:
message:Log Text case1 #json: {"case1-total":26,"case-valid":8,"case-duplicates":16,"case-violations":{"Size":0,"Duration":2,"Length":0,"Speed":0}}
message:Log Text case2 #json: {"case2-processed":10,"case-created":10,"case-updated":0}
message:Log Text case3 #json: {"case3-total":10,"case-valid":7,"case-violations":{"missing":["AAA","BBB"],"Data":["AAA","BBB","CCC"]}}
In order to get all fields out of the messages cleanly, I have a filter like this one for each case:
if "Log Text case1 #json:" in [message] {
mutate { add_field => { "case" => "%%{message}" } }
mutate { gsub => [ "case", "^.* ", "" ] }
}
This creates the following fields, for example:
case.case1-duplicates:16
case.case1-total:26
case.case1-valid:8
case.case1-violations.Size:0
case.case1-violations.Duration:2
case.case1-violations.Length:0
case.case1-violations.Speed:0
I find that extremely annoying, since the Logstash filters have to be expanded with every system extension, so I thought it had to work more generically, e.g. with such a filter:
if "#json" in [message] {
mutate { add_field => { "json_message" => "%%{message}" } }
mutate { gsub => [ "json_message", "^.* ", "" ] }
}
This creates the following fields, for example:
json_message.case1-duplicates:16
json_message.case1-total:26
json_message.case1-valid:8
json_message.case1-violations.Size:0
json_message.case1-violations.Duration:2
json_message.case1-violations.Length:0
json_message.case1-violations.Speed:0
What bothers me, however, is that I have all the cases in the "json_message" field. It would be better if I didn't have to create the "json_message" field at all and could only generate the individual fields from the JSON strings.
For example, the following would be acceptable as a result:
case1-duplicates:16
case1-total:26
case1-valid:8
case1-violations.Size:0
case1-violations.Duration:2
case1-violations.Length:0
case1-violations.Speed:0
I'm probably just too stupid and don't see the solution.
Does anyone here have an idea?
Regards
Thorsten