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