Splunk Search

Count occurences of a field value depending on another field

airmouli
Engager

Hello,

I have a set of data similar to this :

session1 | user1 | computer 1 | start
session2 | user2 | computer 2 | start
session1 | user1 | computer 1 | stop
session2 | user2 | computer 2 | stop
session1 | user1 | computer 1 | start
session3 | user3 | computer 3 | start

I would like to count the number of starts and stops for each session.

session1 | user1 | computer 1 |    2     |       1
session2 | user2 | computer 2 |    1     |       1
session3 | user3 | computer 3 |    1     |       0

Thank you for your help

Tags (2)
0 Karma
1 Solution

kmorris_splunk
Splunk Employee
Splunk Employee

Try something like this:

[YOUR BASE SEARCH HERE] 
| stats count(eval(action="start")) as starts count(eval(action="stop")) as stops by session user computer

I created a field called action for start and stop values, as well as giving the other fields logical names: session; user; and computer.

View solution in original post

kmorris_splunk
Splunk Employee
Splunk Employee

Try something like this:

[YOUR BASE SEARCH HERE] 
| stats count(eval(action="start")) as starts count(eval(action="stop")) as stops by session user computer

I created a field called action for start and stop values, as well as giving the other fields logical names: session; user; and computer.

kmorris_splunk
Splunk Employee
Splunk Employee

I just realized my search was a bit off based on your request. You wanted to know the number of starts and stops per session. That would look more like the following:

[YOUR BASE SEARCH HERE] 
 | stats count(eval(action="start")) as starts count(eval(action="stop")) as stops values(user) as users values(computer) as computers by session

The users and computers fields would have a multivalued list of all distinct values for the user and computer fields. Not sure if that is what you wanted, but probably a good idea since there would be multiple values based on your data sample.

0 Karma

airmouli
Engager

That's exactly what I was looking for ; Thank you very much

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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

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 ...