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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...