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.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...