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 Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...