Splunk Search

Getting counts of each search result over time

chadwell
Explorer

I am trying to determine a way to search for user logins over time to get an idea of application usage.

If I have a set number of user ids, I want to get a count of their logins based on a search string in our logs.

So my search is like this:

"Looking for user based on login/user_id=" "abc123" OR "zxy987"

So this would give me all the logs where each of these users had attempted to login and use the application, it could be multiple times per day and there could be multiple entries per day per user of this search string.

But I would like to chart this on a dashboard with time on the x-axis and individual 'string search match" count aka login count on the y axis.

How would I accomplish this in splunk? Would I need to change my search?

Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

We probably need to look at your raw data to give you accurate suggestion. Here is my attempt without that (assuming user is appear in raw log after string /user_id=. Also recommend adding one or more metadata fields index/sourcetype/host/source in your query for better performance)

index=foo sourcetype=bar "Looking for user based on login/user_id=" "abc123" OR "zxy987"
| rex "login/user_id=(?<user_id>\S+)" 
| timechart count by user_id

View solution in original post

chadwell
Explorer

Thanks for your reply. This is great and works well.
I can now see a table of all the counts per day for each user id.

I have a final question, if I wanted to modify the query to show only the days where a user had logged in and not care about the actual count per day, but only be interested if there was a match per day.

The heatmap looks like a good chart for this, where I can have a color where the user logged in and where a user didn't. Then at the bottom of a table it would be good to have a count of the number of days the user logged in (that is, if they log in 3 times in 1 days just count that as 1).

I hope that makes sense and thanks for you help.

0 Karma

somesoni2
Revered Legend

We probably need to look at your raw data to give you accurate suggestion. Here is my attempt without that (assuming user is appear in raw log after string /user_id=. Also recommend adding one or more metadata fields index/sourcetype/host/source in your query for better performance)

index=foo sourcetype=bar "Looking for user based on login/user_id=" "abc123" OR "zxy987"
| rex "login/user_id=(?<user_id>\S+)" 
| timechart count by user_id
Get Updates on the Splunk Community!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...