Splunk Search

Regex help to extract logname

iamsplunker
Communicator

I'm trying to extract logname from the following. 

So the logname value would be message.log/bblog.log/api.log

Please Note :  When the timestamp date is between10-31 there is no extra space where when the timestamp date is single digit i.e.,(1-9 ) there is an extra space at the beginning of the event.

ex: <10>Jan<space><space>4 15:30:02

       <10>Dec<space>31 15:30:02

Here are the sample events 

<10>Jan  4 15:30:02 a2222xyabcd031.xyz.com app1001-cc-NONPROD 2023-01-04 15:30:02 message.log INFORMATION
apple:73 dev-banana_Guava-[Messaging.Security] [sys] [THE Outbound | outbound|] claimEligibility=false

 

<10>Jan  4 15:30:02 ia2222xyabcd031.xyz.com app1001-cc-NONPROD 2023-01-04 15:30:02 bblog.log INFORMATION
apple:73 dev-banana_Guava-[Messaging.Security] [sys] [THE Outbound | outbound|] claimEligibility=false

 

<10>Dec 31 15:30:04 a2222xyabcd031.xyz.com app1001-cc-NONPROD 2023-01-04 15:30:04 api.log INFORMATION
apple:73 dev-banana_Guava-[Messaging.Security] [sys] [THE Outbound | outbound|] claimEligibility=false

Labels (2)
Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Try this regex.  Change the values of "WARNING" and "ERROR" to match your data.

 (\S+) (?:INFORMATION|WARNING|ERROR)

Note the leading space.

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

ITWhisperer
SplunkTrust
SplunkTrust
| rex "(?<logname>\S+)\s+INFORMATION"
0 Karma

iamsplunker
Communicator

Thanks for your response.

Quick question what if we have different string after the LogName 

For ex: ERROR or WARN

Can we use something like this  ?

| rex "(?<logname>\S+)\s+INFORMATION|WARN|ERROR"

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I would try putting the alternate values in brackets

| rex "(?<logname>\S+)\s+(INFORMATION|WARN|ERROR)"
0 Karma
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!

Index This | What travels the world but is also stuck in place?

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

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...