Is it possible to use the value of one field in a json document as an argument to a conditional statement?
f.ex:
{
value1: "test"
value2: "This is a string with the value test included"
}
if value2 =~ /value1/ then {
string contained "test"
}
Continuing on the same idea. Would it be possible to have a regex as the field value:
{
value1:"test|example"
value2:"String with the word example included"
}
if value" =~ /value1/ then {
string contained either "test" or "example"
}
Or is there any other way to dynamically build the conditional when you don't know the condition before the message has been received for parsing?
Haven't looked into the ruby code options.. Could that be used to solve it?
Have played around a bit with it, and not been able to sort it out yet... so if anyone has any suggestions.
This should read from stdin, and set the field hit to true if it finds the lookfor string in the input.
BUT, no matter what input i give, the resulting output will contain the hit:true field:
08:17:52.807 [LogStash::Runner] ERROR logstash.agent - Cannot create pipeline {:reason=>"Expected one of #, \", ', / at line 13, column 19 (byte 133) after filter {\n if [message] =~ "}
Reason for splitting is just that the first filter is to run on another machine in the pipeline, so i keep them separated for clarity while testing.
And if i just use the filter as you show it behaves in the same way, always adding hit => "true" to the final document printed to stdout:
08:36:07.748 [Api Webserver] INFO logstash.agent - Successfully started Logstash API endpoint {:port=>9601}
This should not add the hit
{
"hit" => "true",
"@timestamp" => 2017-07-25T06:36:23.847Z,
"value2" => "lookfor",
"@version" => "1",
"host" => "host",
"message" => "This should not add the hit"
}
this should add hit as it contains lookfor
{
"hit" => "true",
"@timestamp" => 2017-07-25T06:36:38.114Z,
"value2" => "lookfor",
"@version" => "1",
"host" => "host",
"message" => "this should add hit as it contains lookfor"
}
Didn't get lucky on that one either...
But look on the bright side, this gives me an excuse to start learning ruby as well
Think it should be possible to patch something together using the code option in the filter.
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.