Splunk Search

How to rex the root domain and parse the .TLD from email sender logs?

packet_hunter
Contributor

Scenario: I am trying to list all incoming sender domains and tlds. For example, sender@blah.domain.tld, looking for just "domain" and "tld". For some reason I am not finding the right syntax. I am also not interested in senders from my domain.

enter code
index=mail sourcetype=xemail sender != *@mydomain* | search sender =* | rex field = sender ".*@(?< domain >.*)" | stats list(domain)
here

In addition to the needed rex syntax, please let me know if there is a more efficient way to achieve this.

Thank you

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this

Updated
removed a bracket

index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+\.\w+)$" | stats list(domain)

To get tld as separate field

  index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+)\.(?<tld>\w+)$" | stats list(domain)

View solution in original post

0 Karma

javiergn
Super Champion

What about this (not tested)

| rex field=sender "@(?<domain>[^\.]+).*?(?<tld>[^\.]+)$"
0 Karma

packet_hunter
Contributor

not working

0 Karma

javiergn
Super Champion

Just forced the wildcard to be non-greedy. Try now:

| rex field=sender "@(?<domain>[^\.]+).*?(?<tld>[^\.]+)$"
0 Karma

packet_hunter
Contributor

This works now too. Thanks

0 Karma

somesoni2
Revered Legend

Try something like this

Updated
removed a bracket

index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+\.\w+)$" | stats list(domain)

To get tld as separate field

  index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+)\.(?<tld>\w+)$" | stats list(domain)
0 Karma

packet_hunter
Contributor
| search sender= * | rex field=sender "[@\.]((?<domain>\w+)\.\w+)$" | stats list(domain)

this works for just the root domains, but do you have an example with .tlds in a separate column as well?

Thank you!

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...