Splunk Search

position of a character in a string

jrodriguezap
Contributor

Hello
I'm trying to do a substr to strings such as:

google-public-dns-b.google.com
cachewas.tdp.net.pe
b.resolvers.Level3.net

And give me back the following:

google.com
tdp.net.pe
Level3.net

I thought doing a substr(domain,(mvjoin(domain,"."))
But it turned out, that way it could be achieved?
I would appreciate your support.
Regards

Tags (1)
0 Karma
1 Solution

wrangler2x
Motivator

I'm assuming that you have a field for that FQDN called 'hostname'. If that is not the field name, use what is the field name. If you don't have a field for the FQDN pre-defined, then the answer would be different. This answer assumes you want two levels of the domain name (as in google.com):

... | rex field=hostname "\.(?<s_domainname>\S+\.\S+)$"

View solution in original post

wrangler2x
Motivator

I'm assuming that you have a field for that FQDN called 'hostname'. If that is not the field name, use what is the field name. If you don't have a field for the FQDN pre-defined, then the answer would be different. This answer assumes you want two levels of the domain name (as in google.com):

... | rex field=hostname "\.(?<s_domainname>\S+\.\S+)$"

sowings
Splunk Employee
Splunk Employee

.co.uk 😞

I've thought about working on an app to build up the known TLDs in order to get a correct "domain" mapping, but I never got around to it.

0 Karma

MonkeyK
Builder

old question, but i worked through a similar problem in
This question

Basically, you can use these to get at different subdomain levels

  | rex field=dest_hostname "(?P<ld2>[\w_-]+\.[\w_-]+)$" 
  | rex field=dest_hostname "(?P<ld3>[\w_-]+\.[\w_-]+\.[\w_-]+)$" 
  | rex field=dest_hostname "(?P<ld4>[\w_-]+\.[\w_-]+\.[\w_-]+\.[\w_-]+)$" 
0 Karma

jrodriguezap
Contributor

It's very good.
Thank you very much.

0 Karma

Ayn
Legend

How would you (and thus Splunk) know that the second domain is supposed to be transformed to "tdp.net.pe" and not just "net.pe"?

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