Splunk Search

What is the most efficient way to extract user name from my sample Message fields?

smudge797
Path Finder

What's the most efficient way to extract the user name from these messages:

Message=Self-service Plug-in started (user=DOMAINX\a123456)
Message=Self-service Plug-in started (user=DOMAINY\c123456)

Thanks

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

... | rex field=Message "\(user=(?<user>[^\)]+)"

View solution in original post

ddrillic
Ultra Champion
\\(?<user>(\w|\d+)*) should do it...
0 Karma

smudge797
Path Finder

Error in 'rex' command: Encountered the following error while compiling the regex '(?(\w|\d+)*)': Regex: unmatched parentheses

0 Karma

ddrillic
Ultra Champion

right ; -)

| rex  field=data "\\\(?<user>(\w|\d)*)"

three slashes - the editors mistreat them ....

0 Karma

woodcock
Esteemed Legend

Like this:

... | rex field=Message "\(user=(?<user>[^\)]+)"

smudge797
Path Finder

Nice,

user="DOMAINY\L123456"
Can we drop the domain or separate it?

0 Karma

woodcock
Esteemed Legend

Like this:

 ... | rex field=Message "\(user=(?<domain>[^\\\]+)\\\(?<user>[^\)]+)"
0 Karma

smudge797
Path Finder

Nice thanks!

0 Karma

ppablo
Retired

Hi @smudge797

Glad you found a solution through @woodcock and gave him an upvote, but please don't forget to click "Accept" directly below his answer to resolve the question. Thanks!

0 Karma

smudge797
Path Finder

Done!

Thanks.

richgalloway
SplunkTrust
SplunkTrust

I'm not sure if it's the most efficient, but it's one of the simplest.

... | rex field=Message "\\(?<userName>[^\)]*)" | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The leading backslash needs to be escaped. Otherwise, it escapes the left paren.

---
If this reply helps you, Karma would be appreciated.
0 Karma

smudge797
Path Finder

Error in 'rex' command: Encountered the following error while compiling the regex '\(?[^\)]*)': Regex: unmatched parentheses

0 Karma

jmallorquin
Builder

Hi,

props.conf

[<<sourcetype>>>]
.
.
.

    EXTRACT-user = \\(?<user_wo_domain>[^\)]+)\)$

Hope i help you

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...