I have used kv filter
to extract key-value pairs using field_split
and have used default_keys to provide default keys in case no value is present corresponding to that field.I have used strip of mutate filter to trim all the spaces from the values of the fields.
But for the same field I am getting two different fields one with the default values(that I mentioned using default_keys) and another field with spaces.
I have tried different regex patterns for one or more spaces to be used in trim_key like
"\s", "\s*" , "[ ]{1,}
but nothing worked
My kv filter looks like:--
kv {
source => "kvpairs"
default_keys => ["loc","0",
"time","null",
"action","null",
"orig","null"]
field_split => "|"
trim_key => "[ ]{1,}"
}
My log data looks like:---
loc=1810756|time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
loc =|time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
loc= |time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
loc = 2 | time = 23Jan2018 12:16:52 | action = accept |orig=11.12.13.14|
loc=3|time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
loc=7|time= 23Jan2018 12:16:52| action = |orig=11.12.13.14|
loc=8|time= 23Jan2018 12:16:52| action = |orig=11.12.13.14|
loc=9|time= 23Jan2018 12:16:52| action =|orig=11.12.13.14|
loc=10|time= 23Jan2018 12:16:52|action=accept| orig = 11.12.13.14 |
loc=11|time= 23Jan2018 12:16:52|action=accept|orig= |
loc=12|time= 23Jan2018 12:16:52|action=accept|orig= |
loc=13|time= 23Jan2018 12:16:52| action = accept |orig=|
loc=14|time= 23Jan2018 12:16:52| action = accept |orig=11.12.13.14|
loc=15|time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
loc=16|time= 23Jan2018 12:16:52|action=accept|orig=11.12.13.14|
The output that I should I get in
Case1:When value is not present,e.g action =|
should be -> "action" = "null"
Case2:When one or more spaces are present,e.g. action = |
should be -> "action" = " "