I am ingesting JSON data to logstash, and I am using JSON filter.
In the JSON data, when the KEY is either Value 1 or Value 2, I should add a field, and if this key is missing in the logs, I will have to drop it. Please advise on how to code this.
Below is code, and its not effective.
if "true" in ["adf"] {
mutate {
add_field => {"TrueCondition" => "Test True" }
}
}
if "false" in ["adf"] {
mutate {
add_field => {"FalseCondition" => "Test False" }
}
}
Data captured in the JSON event: "adf": false or "adf": true
Thanks in Advance.
I am using STDOUT to check if the output is as expected.
My objective is - if the Syslog message has the field "adf", then I will perform "add_field", else I should drop the event and not process the event.
Please advise on how to configure this.
The whole code is working except for the IF condition., and I have not implemented the drop condition.
@Badger , yes, my objective is the ADF field is present in the JSON log, then I will mutate and add_field, else I will drop the event.
But the IF condition is not working. Am I calling a Wrong field in IF?
Because when I just add IF, there is change in output, but when I add DROP condition, then the event is being sent to a different port and there by dropped.
The logstash configuration language does not provide a way to directly test whether a boolean field exists. There is an open issue for that. "if [adf]" will evaluate false is [adf] does not exists, but also when [adf] is a boolean with the value false.
The trick is to set a metadata field, then only overwrite it if [adf] exists, then test whether the metadata field was modified.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.