Splunk Search

Help building regex for searches based on cs_username field.

Vfinney
Observer

I'm having no luck building a regex to match cs_usernames. What I'm looking for are two separate searches both based on the
cs_username field. The first search is to find all instances where the usernames are in all CAPS. The second search is to find usernames that end in at least two digits. Example of logs are below:

2020-05-15 04:58:34 10.140.14.228 POST /NotAvailable.aspx - 80 Gerardot 10.140.15.235 Mozilla/5.0+(Linux;+Android+9;+SM-G960U)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/74.0.3729.136+Mobile+Safari/537.36  302 0 0 15 172.69.69.111

2020-05-15 04:57:19 10.140.14.228 POST /Account/Login.aspx - 80 Kaitlyn1230 10.140.15.235 Mozilla/5.0+(iPhone;+CPU+iPhone+OS+13_4+like+Mac+OS+X)+AppleWebKit/605.1.15+(KHTML,+like+Gecko)+GSA/107.0.310639584+Mobile/15E148+Safari/604.1 200 0 0 46 162.158.75.109

2020-05-15 04:54:24 10.140.14.228 POST /PaymentInfo.aspx - 80 Emulbah 10.140.15.235 Mozilla/5.0+(Windows+NT+6.1;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/81.0.4044.138+Safari/537.36  302 0 0 46 172.68.150.39
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @Vfinney,
try the following regex

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+

or using the rex command

your_search
| rex "^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+"
| ...

that you can test at https://regex101.com/r/xyPcQj/1

Ciao.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Vfinney,
try the following regex

^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+

or using the rex command

your_search
| rex "^\d+-\d+-\d+\s+\d+:\d+:\d+\s+\d+\.\d+\.\d+\.\d+\s+\w+\s\/[^ ]+\s+[^ ]+\s+\d+\s+(?<cs_username>[^ ]+)\s+"
| ...

that you can test at https://regex101.com/r/xyPcQj/1

Ciao.
Giuseppe

0 Karma

to4kawa
Ultra Champion

your log is space delimited.

why do not you use \s and \S?

or try Field Extracter

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...