Splunk Search

Field extraction for logs with slightly different field position based on the servername

splunk_worker
Path Finder

Hi All
Here are my sample logs

_time prod-server-1234 web_access 10.11.12.13 "GET /json/some_search?asasa HTTP/1.1" 200 189 "-" "AppEngine-Google; ( some-search-engine; appid: a12334445)" 0.221 "-/-" mydomain

_time test-server-1234 web_access 33.44.55.66 (10.66.77.88) "GET /json/some_search?sdsddd HTTP/1.1" 200 189 "-" "AppEngine-Google; ( some-search-engine; appid: a12334445)" 0.221 "-/-" mydomain

In the 1st event, the server name is prod-server-1234 and the client ip is 10.11.12.13

In the 2nd event the server name is test-server-1234 and the client ip is 10.66.77.88 and destination ip is 33.44.55.66. The destination ip in the 2nd log and client ip in the 1st log are same position.

Note that, event2 has client ip within bracket and the ip after web_access is destination ip.

So, the extraction should be different for server name starts with prod-server-* to extract client ip. The extraction for server names starts with test-server-* should be different for extracting destination ip and client ip.

Note that, the client ip location is different in both formats of the logs. Both logs are same type and coming from same source / log file.

What do I differentiate both server names and extract?

servername format is always fixed.

Tags (2)
1 Solution

MuS
SplunkTrust
SplunkTrust

Hi splunk_worker,

base on your two log examples you can use something like this on your events to get new fields named servername, destIP and clientIP:

your base search to get the events 
| rex field=_raw "\s(?<servername>(prod-server-)\d+|(test-server-)\d+)\s"
| rex field=_raw "web_access\s(?<destIP>(\d+\.){3}\d+)(?=\s\()"
| rex field=_raw "(?<clientIP>(\d+\.){3}\d+)(?=[)\s]+\"GET)"
| table servername destIP clientIP

hope this helps ...

cheers, MuS

View solution in original post

MuS
SplunkTrust
SplunkTrust

Hi splunk_worker,

base on your two log examples you can use something like this on your events to get new fields named servername, destIP and clientIP:

your base search to get the events 
| rex field=_raw "\s(?<servername>(prod-server-)\d+|(test-server-)\d+)\s"
| rex field=_raw "web_access\s(?<destIP>(\d+\.){3}\d+)(?=\s\()"
| rex field=_raw "(?<clientIP>(\d+\.){3}\d+)(?=[)\s]+\"GET)"
| table servername destIP clientIP

hope this helps ...

cheers, MuS

splunk_worker
Path Finder

Thanks a lot. Got it what I wanted.

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...