Splunk Search

Extracting a specific message from a changing field

Michael_Scott
Explorer

Hi everyone. I am a new user to Splunk. 

Recently, I have met some trouble with trying to extract a certain message out from a field I want. I have a field called Message, which logs the message sent to a web server. However, I only want to retrieve a specific field when the message contains the desired field that I want. 

Example: I want to retrieve the user's name when service is invoked. 

TimeMessage
2021-05-15T01:51:52.321ZSession ID 1234 has been created
2021-05-15T01:51:52.321ZInvoked by user David from IP 127.256.25.16
2021-05-15T01:51:52.321ZConfiguration Reading - Start

 

Hence, I only want to extract the name David, when that specific message log containing the name appears. Does anyone have any clue how I can extract that field specifically when it appears?

Thanks in advance. 

EDITED:
Hey Splunk Users, 

If you met the same problem as I did, where the message logs change constantly, do make sure to search for the message you are looking for first, before drilling down for the specific field. 

In my case:
| search Message="Invoked by user *"
| rex field=Message "Invoked by user (?<user>\w+)"

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

If the user is just a single word

 

| rex field=Message "Invoked by user (?<user>\w+)"

 

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Depending on your actual events, this might work

| rex "Invoked by user (?<user>.+)"
0 Karma

Michael_Scott
Explorer

Well the full message is usually like this:

Message
Invoked by user David from IP 10.143.235.76


I did try to extract the name and the IP Address at the same time, but it still does not extract it as intended.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If the user is just a single word

 

| rex field=Message "Invoked by user (?<user>\w+)"

 

Michael_Scott
Explorer

Hi there, sorry for getting back to you a bit late. 

I actually had to add another line in my query, which is 

| search Message="Invoked by user *"
| rex field=Message "Invoked by user (?<user>\w+)"

This will first return the message I'm looking for, and the user in the message. Thanks a lot for the assistance. 

0 Karma
Get Updates on the Splunk Community!

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...

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 ...

Splunk App for Anomaly Detection End of Life Announcement

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...