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
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...