Splunk Search

getting vice-versa hostnames from events

schose
Builder

Hi all,

I'm getting in events looking like this from host srv01.dev.web.env

env_web_dev_srv01.cpu-0.cpu-idle 97.380109 1431000659
env_web_dev_srv01.cpu-3.cpu-idle 99.026781 1431000659
env_web_dev_srv01.cpu-2.cpu-idle 98.903448 1431000659
env_web_dev_srv01.cpu-1.cpu-idle 98.456780 1431000659

as you can see the hostname is written vice-versa. Now i'm using props and transforms to get the hostname from the event:

props.conf:

[collectd]
TIME_PREFIX = ^.+\..+\..+\s.+\s
TRANSFORMS-mask= mask-collectd
SHOULD_LINEMERGE=false

transforms.conf:

[mask-collectd]
REGEX = ^([^_]+)_([^_]+)_([^_]+)_([^_.]+)\..+\..+\s.+\s.+
DEST_KEY = MetaData:Host
FORMAT =  host::$4.$3.$2.$1

my issue is that now the "." in a hostname have to match 3: so srv01.dev.web.env works find but srv01.subdomain.dev.web.env is not working.

Is there a smarter way to reverse the hostname and replace "_" with "." at index time?

Regards,

Andreas

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Make the fourth level optional with a regex like ^(?:([^_]+)_)?([^_]+)_([^_]+)_([^_]+)_([^_.]+)\.

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...