Splunk Search

How to search for only select users based on a regex extract

LizAndy123
Path Finder

So I have the following setup and everything is good but I want to kind of do a subsearch

In the Event - Sample

User-ABCDEF assigned Role-'READ' on Project-1234 to GHIJKL

Current SPL 

index="xxxx" "role-'WRITE'" OR "role-'READ'"
| rex "User-(?<userid>[^,]*)"
| rex "(?<resource>\w+)$"
| eval userid=upper(userid)
| stats c as Count latest(_time) as _time by userid

I get an output as this

ABCDEF ASSIGNED ROLE-'READ' ON PROJECT-1234 TO GHIJKL

 

What I want is to search on just the GHIJKL after it extracts or should I just put it at the front so it only fetches that?

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

To search on the resource field, use the where command.

index="xxxx" "role-'WRITE'" OR "role-'READ'"
| rex "User-(?<userid>[^,]*)"
| rex "(?<resource>\w+)$"
| where resource="GHIJKL"
| eval userid=upper(userid)
| stats c as Count latest(_time) as _time by userid

 

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

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Your sample event doesn't appear to have a comma terminating the user id so perhaps use this rex to extract it?

| rex "User-(?<userid>[^, ]*)"

richgalloway
SplunkTrust
SplunkTrust

To search on the resource field, use the where command.

index="xxxx" "role-'WRITE'" OR "role-'READ'"
| rex "User-(?<userid>[^,]*)"
| rex "(?<resource>\w+)$"
| where resource="GHIJKL"
| eval userid=upper(userid)
| stats c as Count latest(_time) as _time by userid

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL

Splunk AI Assistant for SPL | Key Use Cases to Unlock the Power of SPL  The Splunk AI Assistant for SPL ...

Buttercup Games: Further Dashboarding Techniques (Part 5)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Customers Increasingly Choose Splunk for Observability

For the second year in a row, Splunk was recognized as a Leader in the 2024 Gartner® Magic Quadrant™ for ...