1

I am trying to parse a custom log line using grok pattern but I'm not able to completely parse the line.

Custom log line:

site 'TRT' : alias 'TRT,FAK,FAS,ATI,ONE,DVZ,TWO' : serveur 'Test10011' RAS : TRT / TRT serveur 'Test10011' OK

Grok pattern:

%{DATA:site}\:%{DATA:alias}\:%{DATA:server}\:%{DATA:msg}

Result:

{
  "site": [
    [
      "site 'TRT' "
    ]
  ],
  "alias": [
    [
      " alias 'TRT,FAK,FAS,ATI,ONE,DVZ,TWO' "
    ]
  ],
  "server": [
    [
      " serveur 'Test10011' RAS "
    ]
  ],
  "msg": [
    [
      ""
    ]
  ]
}

I am not able to parse the last few items in the 'msg', . Could you please help ,where I'm going wrong? msg should contain "TRT / TRT serveur 'Test10011' OK"

0

1 Answer 1

1

It seems you just need to use GREEDYDATA instead of DATA pattern:

%{DATA:site}\s*:\s*%{DATA:alias}\s*:\s*%{DATA:server}\s*:\s*%{GREEDYDATA:msg}

I also suggest adding \s* around : to get rid of leading/trailing whitespaces. enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @Wiktor. Didn't consider GREEDYDATA before :)
Yeah, GREEDYDATA is translated to the .* pattern (a greedy dot matching pattern), and DATA is translated into .*? (lazy dot matching pattern). You may read more about greedy and lazy quantifiers here.
One last thing. In case if I want only 'OK' in 'msg' label how would I remove the characters before OK?
If that word is always at the end and is always preceded with a space, replace the last \s* with .*\s (%{DATA:site}\s*:\s*%{DATA:alias}\s*:\s*%{DATA:server}\s*:.*\s%{GREEDYDATA:msg})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.