Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logstash config: check if boolean field exists

Tags:

logstash

Using Logstash 1.4.2, I have a field myfield that is a boolean value in my JSON document.

To check if it exists (don't care about the boolean value) I used:

if[myfield] { ...exists... } else { ...doesn't exist... } 

The results from testing this conditional statement are:

[myfield] does not exist   --> false
[myfield] exists, is true  --> true
[myfield] exists, is false --> false //expected true because the field exists

It is checking the boolean value, not its existence.

How can I check that a boolean field exists?

like image 412
bradvido Avatar asked Oct 09 '14 20:10

bradvido


1 Answers

Kind of lame that it doesn't work right out of the box, but you can hack it like this -- add a string representation of the boolean, compare against the string, and then remove the added field:

filter {
   mutate {
     add_field => { "test" => "%{boolean}" }
   }
   if [test] == 'true' or [test] == 'false' {
     // field is present and set right
   } else {
     // field isn't present or set to something other than true/false
   }
   mutate {
     remove_field => [ "test" ]
   }
}
like image 78
Alcanzar Avatar answered Sep 20 '22 11:09

Alcanzar