Splunk Search

DNS Logs field extraction (flags)

kvnpichon
Path Finder

Hello Splunkers,

I'm actually trying to extract the "flags" field in the DNS logs.

Meanwhile, the TA provided by Splunk isn't working properly because all logs haven't the same form.

This is the regex provided by Splunk to extract flags field :

 

 

(?<operation>[ R]) (?<opcode>.) \[(?<hexflags>[0-9A-Fa-f]+) (?<flags>....) (?<response>[^\]]+)\]

 

 

Log form case 1 : 

 

 

R Q [8381 A DR NXDOMAIN]

 

 

Log form case 2 :

 

 

R Q [8081 DR NOERROR]

 

 

Log form case 3 :

 

Q [0001 D NOERROR]

 

In the case 1 the extract work properly and the field "flags=A DR" but in the case 2 or 3 none of the fields are extracted (because there are only 3 digits in the [] instead of 4).

Any idea how to process to extract these values ?

Labels (1)
Tags (2)
0 Karma
1 Solution

kvnpichon
Path Finder

Hello,

I tried your solution but it doesn't work.

So I splitted my regex into 2 parts :

Regex 1 : 

 

(?<opcode>.) \[(?<hexflags>[0-9A-Fa-f]+) (?<flags>....|...|..|.) (?<response>[^\]]+)\]

 

It extracts :

  • opcode field
  • hexflags field
  • flags field
  • response field

Regex 2 : 

 

....\s(?<operation>[R])\s

 

 It extracts :

  • operation field

And now it works properly !

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

 

(?<operation>[ R]) (?<opcode>.) \[(?<hexflags>[0-9A-Fa-f]+) (?<flags>.+) (?<response>[^\]]+)\]

hexflags as anchored to the [ and response is anchored to the ] leaving flags to pick up the bit in between

 

0 Karma

kvnpichon
Path Finder

Hello,

I tried your solution but it doesn't work.

So I splitted my regex into 2 parts :

Regex 1 : 

 

(?<opcode>.) \[(?<hexflags>[0-9A-Fa-f]+) (?<flags>....|...|..|.) (?<response>[^\]]+)\]

 

It extracts :

  • opcode field
  • hexflags field
  • flags field
  • response field

Regex 2 : 

 

....\s(?<operation>[R])\s

 

 It extracts :

  • operation field

And now it works properly !

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...