Splunk Search

Extracting users from a list

ryangillan
Explorer
2020-10-19 05:00:03,744 INFO main() Deletion list: ['user1', 'user2', '$template', 'user233', 'svc_user1', ]

 I have this log file that outputs a list of users to be deleted.
I want to search this output and extract the users into fields then exclude the $template* & svc_users* users.

I have tried this to extract the users to field.

  search "list:" | eval del_users=split(_raw,"', '") | table del_users

output looks like:

2020-10-19 05:00:03,744 INFO main() Deletion list: ['user1
user2
$template
user233
svc_user1
 

Any suggestions to get a better output or how I should be doing this?

Labels (2)
1 Solution

vnravikumar
Champion

Hi

Try this

| rex field=log max_match=0 "\[{0,}\'(?P<output>[^',]+)" 
| mvexpand output 
| table output

View solution in original post

ryangillan
Explorer

This looks like what I need.

|search "list:" | rex field=log "\[(?<del_users>.*)\, \]" | eval users=split(_raw,"', '") | mvexpand users
|search NOT users IN ("$*templat*","svc*") | table users

 

vnravikumar
Champion

Hi

Try this

| rex field=log max_match=0 "\[{0,}\'(?P<output>[^',]+)" 
| mvexpand output 
| table output

inventsekar
SplunkTrust
SplunkTrust

did you check the "rex" regular expression...

 

| makeresults 
| eval log="2020-10-19 05:00:03,744 INFO main() Deletion list: ['user1', 'user2', '$template', 'user233', 'svc_user1', ]" 
| rex field=log "\[(?<del_users>.*)\, \]" 
| table del_users

 

EDIT - verified and adding the screenshot:rex-del-users.jpg

 

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...