Splunk Search

I am trying to create a field for sudo based on the following log entry

gceraso
Engager

I am trying to extract the username into a field that I can use and have so far been unsuccessful. I am doing this based off the log entries below.

Mar  4 17:20:43 hostname sudo: [ID 702911 local2.notice]    username : TTY=pts/3 ; PWD=/export/home/username ; USER=root ; COMMAND=/usr/bin/su -    
Mar  7 11:44:47 hostname sudo: [ID 702911 local2.notice]   user : TTY=pts/5 ; PWD=/export/home/user ; USER=root ; COMMAND=/usr/bin/su -

I have tried this search and regex but have been unsuccessful. If the username is a different length it won't pick it up. Also, it doesn't seem to pick up all occurrences of the same name either.

sudo "COMMAND=/usr/bin/su"
| rex "(?i)\\.notice\\]   (?P<FIELDNAME>\\w+\\s+:)"
| fields FIELDNAME
| dedup FIELDNAME
Tags (1)
0 Karma

Stephen_Sorkin
Splunk Employee
Splunk Employee

Try something like:

sudo "COMMAND=/usr/bin/su"
| rex "\\]\s+(?<FIELDNAME>\S+)"
| dedup FIELDNAME
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, ...