Splunk Search

Combining records with the same date

Dabob
Engager

I have a search that I am using for tracking VPN connection and I have found that I have users having multiple connections throughout a day and I would like to add the same day connections together.

 

Here is what I get from my search. 

userDurationTermination Reason_timeLocationIP
jhicks0h21m23sUser Requested2021-03-25T14:43:48.000-0400Waverly, United States
jhicks0h31m16sIdle Timeout2021-03-25T14:15:42.000-0400Waverly, United States
jhicks0h09m49sUser Requested2021-03-25T13:23:03.000-0400Waverly, United States
jhicks1h53m07sIdle Timeout2021-03-25T12:57:42.000-0400, United States
jhicks2h27m12sIdle Timeout2021-03-24T15:32:43.000-0400, United States


and here is kind of what I am looking for. just adding the Duration fields together if they occur on the same day 

jhicks2h55m35sIdle Timeout2021-03-25, United States
jhicks2h27m12sIdle Timeout2021-03-24, United States

 

 

Here is what my search looks like 

Cisco_ASA_message_id=113019 NOT "AnyConnect-Parent"
| transaction user endswith="Duration:" keepevicted=true
| eval full_duration = duration_hour."h".duration_minute."m".duration_second."s"
| eval Start_time=strftime(_time,"%Y/%m/%d %H:%M:%S"), End_time=(strftime(_time + duration,"%Y/%m/%d %H:%M:%S")), Total_time=if(isnull(full_duration), Start_time." --> current session",Start_time." --> ".End_time)
| mvexpand src | iplocation src | eval LocationIP=City.", ".Country
| stats values(host) as host values(Total_time) as "Session Time" values(src) as "PublicIP" values(LocationIP) as LocationIP values(assigned_ip) as "Assigned IP" values(reason) as "Termination Reason" values(bytesMB) as bytesMB values(bytes_inMB) as bytes_inMB values(bytes_outMB) as bytes_outMB values(full_duration) as Duration by _time, user
| sort -_time
| search PublicIP=* |search user=$_user$
| table user Duration "Termination Reason" _time LocationIP "PublicIP" Duration

Labels (4)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust
Cisco_ASA_message_id=113019 NOT "AnyConnect-Parent"
| transaction user endswith="Duration:" keepevicted=true
| eval full_duration = duration_hour."h".duration_minute."m".duration_second."s"
| eval Start_time=strftime(_time,"%Y/%m/%d %H:%M:%S"), End_time=(strftime(_time + duration,"%Y/%m/%d %H:%M:%S")), Total_time=if(isnull(full_duration), Start_time." --> current session",Start_time." --> ".End_time)
| mvexpand src | iplocation src | eval LocationIP=City.", ".Country
| bin span=1d _time
| stats values(host) as host values(Total_time) as "Session Time" values(src) as "PublicIP" values(LocationIP) as LocationIP values(assigned_ip) as "Assigned IP" values(reason) as "Termination Reason" values(bytesMB) as bytesMB values(bytes_inMB) as bytes_inMB values(bytes_outMB) as bytes_outMB sum(full_duration) as Duration by _time, user
| sort - _time
| search PublicIP=* |search user=$_user$
| table user Duration "Termination Reason" _time LocationIP "PublicIP" Duration

I presume from the use of $_user$ that this is part of a dashboard.  If so, the search can be made more efficient by moving search user=$_user$ to before the first | or as early in the search as possible.

Try using the bin command to round _time to the beginning of the day.  Then stats can be used to add up the durations.

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust
Cisco_ASA_message_id=113019 NOT "AnyConnect-Parent"
| transaction user endswith="Duration:" keepevicted=true
| eval full_duration = duration_hour."h".duration_minute."m".duration_second."s"
| eval Start_time=strftime(_time,"%Y/%m/%d %H:%M:%S"), End_time=(strftime(_time + duration,"%Y/%m/%d %H:%M:%S")), Total_time=if(isnull(full_duration), Start_time." --> current session",Start_time." --> ".End_time)
| mvexpand src | iplocation src | eval LocationIP=City.", ".Country
| bin span=1d _time
| stats values(host) as host values(Total_time) as "Session Time" values(src) as "PublicIP" values(LocationIP) as LocationIP values(assigned_ip) as "Assigned IP" values(reason) as "Termination Reason" values(bytesMB) as bytesMB values(bytes_inMB) as bytes_inMB values(bytes_outMB) as bytes_outMB sum(full_duration) as Duration by _time, user
| sort - _time
| search PublicIP=* |search user=$_user$
| table user Duration "Termination Reason" _time LocationIP "PublicIP" Duration

I presume from the use of $_user$ that this is part of a dashboard.  If so, the search can be made more efficient by moving search user=$_user$ to before the first | or as early in the search as possible.

Try using the bin command to round _time to the beginning of the day.  Then stats can be used to add up the durations.

 

---
If this reply helps you, Karma would be appreciated.
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!

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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