logstash - Catching a comma seperated pattern with Grok -


i parsing though set of logs 1 field giving me issues. format

header(ip, date etc.) field1=data, field2=data, field3=data, field4=data have general parser read

match => [ "message","%{data:..header..} %{data}=%{data:service},%{data}=%{data:roles}],%{data}=%{data:macaddress},%{data}=%{data:nasip}"] 

some times "value" portion "roles" field looks value, [admin]. handled ] in %{data}=%{data:roles}], in other cases get

subvalue1, subvalue2, subvalue3,  

or

subvalue1, subvalue2, subvalue3, subvalue4,  

or

subvalue1, subvalue2,  

and parser captures subval1. can see.. there variable number of sub vals , hard catch when ] missing.

here example of kind of log creating issues:

local1--debug--10.47.130.2--2017-03-24--2017-03-24t11:29:51-‌​04:00--11:29:51,545 10.241.186.253 ztp0 session 20 1 0 common.username=labf5chk,common.service=f5_healthchk,common.‌​roles=employee, [user authenticated],common.nas-ip-address=xxxxxxxxxxxx,common.req‌​uest-timestamp=2017-‌​03-24 11:27:56-04 

is there work around this?

for variable length comma separated data suggest capturing whole set of values 1 field , parsing field using csv filter.

for parsing set of key=value pairs suggest using kv filter.

so config work this

filter {   grok {     match => [ "message","%{data:..header..} %{greedydata:kv_pairs}"]   }   kv {     source => "kv_pairs"     field_split => ","   }   csv {     # assumes key 'roles'     source => "roles"     target => "role_list"   } } 

i not sure of exact format of log messages, kv filter might screw if messages have format, doesn't separate subvalue csv list list of k=v pairs this:

...,key=value,roles=subval1,subval2,subval3,key2=value2... 

or opens list [ doesn't close it.

edit: looks though first breaking case in fact you're facing.

if roles section in same place, followed same key, match using

...common.‌​roles=%{data:roles},common.nas-ip-address=%{data:nasip}... 

if these kv pairs consitently in same arrangement, using pattern should work. if field @ consistent or matchable more specific regex .*? should use that, use actual key names/patterns instead of %{data}= tempts mismatching.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -