Splunk Search

Can the transaction command be used to search the duration a user has been logged in to a PC?

sbattista09
Contributor

I want to see the duration that a user has been logged in to the PC for. Would the transaction command work the best in this situation?

Here is my base search that I am going to go off of:

index=A host=Domain-controller  Account_Name=UserA TaskCategory=Logoff OR TaskCategory=Logon | eval k8targetaccount=mvindex(Account_Name, 1) | rename k8targetaccount as Account_Names  | table  _time Account_Names Source_Network_Address TaskCategory
0 Karma
1 Solution

sundareshr
Legend

Yes, the transaction command will work. You could do something like this

.... | transaction Account_Names startswith="login" endswith="logout" |  table Account_Names  duration

Having said that, this may or may not not be the most efficient commands for this purpose. For example

... | stats earliest(_time) as login latest(_time) as logout by Account_Names | eval duration = if(logout=login, now()-login, logout-login) | ...

may be faster, but that depends on your data. How many times could a user login/logout in a day etc. To handle multiple login/logout, you could use streamstats or eventstats commands. To give the best solution, we will need to see some data

View solution in original post

sundareshr
Legend

Yes, the transaction command will work. You could do something like this

.... | transaction Account_Names startswith="login" endswith="logout" |  table Account_Names  duration

Having said that, this may or may not not be the most efficient commands for this purpose. For example

... | stats earliest(_time) as login latest(_time) as logout by Account_Names | eval duration = if(logout=login, now()-login, logout-login) | ...

may be faster, but that depends on your data. How many times could a user login/logout in a day etc. To handle multiple login/logout, you could use streamstats or eventstats commands. To give the best solution, we will need to see some data

sbattista09
Contributor

the type of data i am dealing whit are AD logs.

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...