Splunk Search

Regex expression to extract IP from a raw log file

ssaini5
Explorer

Hi all,

I am trying to extract an IP and the word "HOST_NAME" from a raw log file using the following regex expression: 

source="/var/tmp/test.log" | rex field=_raw "(?<HOST_NAME>) \b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b"

 

Log file:

EXEC_ID: HOST_NAME: 172.19.20.60 USER_NAME: test ================================  TestCaseRunner Summary ----------------------------- Time Taken: 13844ms Total TestSuites: 2 Total TestCases: 6 (0 failed) Total TestSteps: 16 Total Request Assertions: 19 Total Failed Assertions: 0 Total Exported Results: 0

 

The search results are not extracting the HOST_NAME field and the respective IP. Please suggest what should I change. 

Thank you 

 

Labels (3)
0 Karma
1 Solution

thambisetty
SplunkTrust
SplunkTrust

Try changing second hostname in rex command. Say test for example and and see if you are getting ip into it.

————————————
If this helps, give a like below.

View solution in original post

thambisetty
SplunkTrust
SplunkTrust

| rex “HOST_NAME:\s+(?<HOST_NAME>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})”

————————————
If this helps, give a like below.

ssaini5
Explorer

Hi @thambisetty ,

 

Thanks for the reply. The search is working but the field "HOST_NAME" is still not extracted as a separate field on which I can filter on further.  

0 Karma

thambisetty
SplunkTrust
SplunkTrust

Try changing second hostname in rex command. Say test for example and and see if you are getting ip into it.

————————————
If this helps, give a like below.

ssaini5
Explorer

That worked thanks a ton 🙂 

0 Karma

thambisetty
SplunkTrust
SplunkTrust

Great.

Up vote is rally appreciated.

————————————
If this helps, give a like below.
0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

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

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...