Splunk Search

summarize stats by month

mvasquez21
Path Finder

I have this search to see logins to our splunk environment:

  index = _audit user="*" action="login attempt" info=succeeded | stats count by user

mgmt is asking to see the same data but instead of a "count" column, they want a column for each month. I assume it will be a table of some sort but can't figure out the date summarizing.

Here is an example of the individual entry:

Audit:[timestamp=03-03-2025 09:10:52.577, user=xxxxxx, action=login attempt, info=succeeded reason=user-initiated useragent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" clientip=xxx.xxx.xxx.x" method=LDAP" session=17a169464fada764a1bac7310cac4c47]

columns should be:  user   monthA    monthB   monthc

with the counts under each month

Thanks!

Labels (4)
0 Karma
1 Solution

kiran_panchavat
Champion

@mvasquez21 

Don't append makeresults in your query:-

Use this 

index = _audit user="*" action="login attempt" info=succeeded
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval month=strftime(_time, "%b %Y")
| chart count over user by month
Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!

View solution in original post

mvasquez21
Path Finder

that last one seems to undo the month summarizing

mvasquez21_0-1741019322688.png

 

0 Karma

mvasquez21
Path Finder

one last thing. this is listing the months alphabetically. any way to do it chronologically?

mvasquez21_0-1741017367701.png

 

0 Karma

kiran_panchavat
Champion

@mvasquez21 

Yes, you can definitely display the months chronologically instead of alphabetically. To achieve this, you need to convert the month representation (e.g., "Jan 2024") into a sortable format, like a timestamp or a year-month string (e.g., "2024-01").

index = _audit user="*" action="login attempt" info=succeeded
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval month=strftime(_time, "%Y-%m-%d"), sort_month=strftime(_time, "%Y-%m-%d")
| chart count over user by month
| sort + sort_month
Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

kiran_panchavat
Champion

@mvasquez21 

Refer my output:-

kiran_panchavat_0-1741018212912.png

 

Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

mvasquez21
Path Finder

when i try to append my search with it i get this error: Error in 'makeresults' command: This command must be the first command of a search.

index = _audit user="*" action="login attempt" info=succeeded | makeresults count=20
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval user="user".tostring(1+random()%5)
| eval action="login attempt", info="succeeded"
| eval month=strftime(_time, "%b %Y")
| chart count over user by month

 

0 Karma

kiran_panchavat
Champion

@mvasquez21 

Don't append makeresults in your query:-

Use this 

index = _audit user="*" action="login attempt" info=succeeded
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval month=strftime(_time, "%b %Y")
| chart count over user by month
Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!

mvasquez21
Path Finder

perfect! you are a geniius

0 Karma

mvasquez21
Path Finder

when using this one:

| makeresults count=20 
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval user="user".tostring(1+random()%5)
| eval action="login attempt", info="succeeded"
| eval month=strftime(_time, "%b %Y")
| chart count over user by month

my results don't show the username:

mvasquez21_0-1741016486381.png

 

0 Karma

kiran_panchavat
Champion

@mvasquez21 

makeresults is a command in Splunk that generates synthetic (fake) data for testing, debugging, and query development without using an actual index. You have to pass your original query. 

 

Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

kiran_panchavat
Champion

@mvasquez21 

You have to use this query:

index = _audit user="*" action="login attempt" info=succeeded
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval month=strftime(_time, "%b %Y")
| chart count over user by month
Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

kiran_panchavat
Champion

@mvasquez21 

Try this 

index = _audit user="*" action="login attempt" info=succeeded
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval month=strftime(_time, "%b %Y")
| chart count over user by month

 

Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

mvasquez21
Path Finder

could i ask of you to paste that so my bad typing doesn't mess it up? Thanks so much!

 

0 Karma

kiran_panchavat
Champion

@mvasquez21 

| makeresults count=20 
| eval _time=relative_time(now(), "-".(random()%180)."d")
| eval user="user".tostring(1+random()%5)
| eval action="login attempt", info="succeeded"
| eval month=strftime(_time, "%b %Y")
| chart count over user by month
Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma

kiran_panchavat
Champion

@mvasquez21 

kiran_panchavat_0-1741015558161.png

 

Did this help? If yes, please consider giving kudos, marking it as the solution, or commenting for clarification — your feedback keeps the community going!
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...