Splunk Search

Eval RegEx for Host Name from FQDN

jhayIV
Engager

Is there a way to write an eval to pull back host name Server1 from Server1.12.city.net

Tags (2)
0 Karma

somesoni2
Revered Legend

You can use eval or rex to get the server name. Assuming host name is first portion in FQDN which is dot separated, try this (say hostname is the field name which contains FQDN, change the field name per your need)

your base search | eval hostname=mvindex(split(hostname,"."),0) 

or

your base search | eval hostname=replace(hostname,"^([^\.]+).+","\1") 

or

your base search | rex field=hostname "^(?<hostname>[^\.]+)"

gokadroid
Motivator

Can you please try this:

your query to return the events
| rex "\s*(?<serverName>[^\.]+)\.(?<remainingPart>[\S]+)"
| table serverName

If city.net always comes as a suffix, this might also work:

your query to return the events
| rex "\s*(?<serverName>[^\.]+)\.(.+\.)*city\.net"
| table serverName
0 Karma
Get Updates on the Splunk Community!

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!

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

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...