Getting Data In

host_regex problem

a212830
Champion

Hi,

I'm trying to parse the host from my logfile name, using host_regex, but it's not matching, and I'm unsure why.

My host_regex setting is: host_regex = \system-(.+).log$

My files are in the format /apps/logs/YYYY/MM/DD/system-HOSTNAME.log

The hostname can be anything - underscores, dashes, numbers, letters, uppercase, lowercase.... About the only two things that I would exclude would be spaces and special characters.

For example:

/apps/logs/2014/07/02/system-ltmblahqa02.log
/apps/logs/2014/07/02/system-ltmrEHH01-old.log
/apps/logs/2014/07/02/system-sD-9k-99sum.log

Tags (2)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Do post your entire inputs.conf stanza.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I think your host_regex string is only missing a backslash to escape the '.log'. This worked for me in RegExr:

system-(?<hostname>[\S]+)\.
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Thanks for setting me straight.

---
If this reply helps you, Karma would be appreciated.
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

I hate to again nag about backslashes and dots, but in that case you'd need a backslash before the dot... else the no-spaces would match all the way to ".lo", and the dot would match the "g" 😛

I don't think the expression in and of itself is the issue. a\d+, do post your entire inputs.conf stanza.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

If by "that" you mean martin_mueller's screen shot, don't worry about it. He's showing I was incorrect about the need to escape periods.
Put 'system-([\S]+).' as your host_regex string. I've had better luck when I avoid matching on '.'.

---
If this reply helps you, Karma would be appreciated.
0 Karma

a212830
Champion

How would you put that in the inputs.conf? Am I missing something?

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

The backslash shouldn't fix things, only disallow examples like this:

/apps/logs/2014/07/02/system-ltmblahqa02_log

Works for me with or without the backslash:

alt text

Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...