Splunk Search

How to extract user email from raw message and assign to a field?

vaishalireddy
New Member



This looks easy but I couldn't figure it out. Any help is appreciated.
How to extract user email from raw message and assign to a field?
For example, here is my event message

message: SpeciaService: Received  Status for xxxxxxx Message=xxx(timeStamp=xxxx, job=1234(super=xxxx(id=1376, userId=xxxxx@xxxx.com , status = success)

I want to generate a table with userId and status fields  generated from event logs that matches 'SpeciaService' events

I tried below, it didn't work

index=xxxx-* SERVICE="xxx-service" | rex field=SpeciaService: Exception "\S* (?<userId>\S*)"  |eval status = if(exception, error:success )| table userId, status

Labels (3)
Tags (1)
0 Karma

lnn2204
Path Finder

Or you can try this:

baseSearch
| rex field=_raw "\suserId\=(?<userId>.*?)\s\,"
0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @vaishalireddy,

you should already have the field extraction of userId and status because Splunk automatically extract the pairs fieldname=value, in this case you have only to use the table command.

If instead ou don't have fields, you have to extract them using a regex like this:

 

your_search
| rex "userId\=(?<userId>[^\@]*\@[^ ]*)\s+,\s+status\s+\=\s+(?<status>[^\)]*)"
| table userId status

you can test the regex at https://regex101.com/r/vKPdDK/1 

 

if the format of the message can change use two separated regexes to extarct your two fields.

Ciao.

Giuseppe

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Given the example event, try this

| regex "SpeciaService:"
| rex "userid=(?<userid>[^, ])"
| rex "status\s=\s(?<status>\w+)"
| table userid status

However, the format of the log looks odd - if the above doesn't work, please provide an accurate representation of your events.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...