简体   繁体   中英

how to parse dynamic logs using grok and logstash?

I 'm new in logstash and grok and trying to parse logs that look like this:

2019-10-23 08:44:38.457  INFO 99999 [ID1=645ae2ae-a9a6-412f-b079-f0495aa9b713, ID2=62702, ID3=3e37ee7c-4e09-4924-be2f-66008dd19032] ---
2019-10-23 08:44:38.796 DEBUG 99999 [ID1=6cf44468-5baa-470b-9ee2-2aa7a74a858f] ---
2019-10-23 08:44:38.849 DEBUG 99999 [ID3=5766d625-366b-4ce6-9a3a-f5e5db3ea65d, ID1=6cf44468-5baa-470b-9ee2-2aa7a74a858f] ---

UUID1 can be first or last. UUID2 might not be present.

How could I parse with grok and keep all UUIDs if present?

Thanks in advance.

I would not use grok for that. I am sure it can be done, since you can have optional fields in a grok pattern, but I think dissect is a better match...

    dissect { mapping => { "message" => '%{[@metadata][timestamp]} %{+[@metadata][timestamp]->} %{level} %{pid} [%{[@metadata][kvStuff]}] %{}' } }
    date { match => [ "[@metadata][timestamp]", "YYY-MM-dd HH:mm:ss.SSS" ] }
    kv { source => "[@metadata][kvStuff]" field_split => "," trim_key => " " }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM