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

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...