Splunk Search

Extract domains from raw data into a new field and create a table with count

lilvermi
New Member

I have raw data, I would like to search for domains within the data, output it to a field and then run stats to show a count of each unique domain. 

Example of raw data:

"This investigation is really great and we found the suspicious domain google.com"

I would like to:
1. search for domains within raw data and output the domain to a field that I can show in a table (Lets call it "Domain")
2. run stats that show the number of occurrences

So ideally, my finished result would be:

Domaincount
google.com50
yahoo.com30

 

Any assistance is greatly appreciated, thank you. 

Labels (3)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Key is how to recognise a domain. You can google for regex to extract domains and get some examples, but this search will show you how to get started

| makeresults
| eval d=split("google.com,abc.net.au,bbc.co.uk,google.com,splunk.com,www.nytimes.com", ",")
| mvexpand d
| rex field=d "(?<domain>(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9])"
| stats count by domain

In your example, use rex field=_raw rather than 'd' in the above.

If you might have more than one domain in your raw data then add the 'max_match=0' to the rex statement

 

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 ...