Splunk Search

How to create a start time from only an end time and duration?

jmaple
Communicator

I'm trying to create a table of VPN connection statistics where the easiest way to see the data is to look at the time the VPN tunnel is closed (_time) and the duration field from our ASA.

2016-06-08T13:31:27-04:00 firewall01 : %ASA-4-113019: Group = user_group, Username = jmaple, IP = 10.10.18.1, Session disconnected. Session Type: SSL, Duration: 7h:12m:31s, Bytes xmt: 418441224, Bytes rcv: 86574259, Reason: User Requested

What I want to do it extract the duration and subtract it from _time to produce a "Start Time" for when the connection started without having to look for a corresponding start event. The calculation would be done by calculating the difference at the time of the search. I'm still trying to get familiar with the ways of producing this kind of thing but everything I've tried so far hasn't worked.

0 Karma
1 Solution

sundareshr
Legend

To get the start time, you will first have to convert Duration & the _time fields to seconds. Then do the subtract. Here's one way to do that

| rex "Duration: (?<h>\d+)h:(?<m>\d+)m:(?<s>\d+)s," | fillnull value=0 h m s | eval duration=h*(60*60)+m*60+s | eval end=_time | eval start=end-duration | eval start=strftime(start, "%x %X")

View solution in original post

sundareshr
Legend

To get the start time, you will first have to convert Duration & the _time fields to seconds. Then do the subtract. Here's one way to do that

| rex "Duration: (?<h>\d+)h:(?<m>\d+)m:(?<s>\d+)s," | fillnull value=0 h m s | eval duration=h*(60*60)+m*60+s | eval end=_time | eval start=end-duration | eval start=strftime(start, "%x %X")

jmaple
Communicator

That works awesome. Now would I be able to convert duration back to its original string without breaking the calculation so it can be inserted into the table as it is in the ASA log?

0 Karma

sundareshr
Legend

You can string it back together like this

.... | eval Duration=h."h:".m."m:".s."s"
0 Karma

jmaple
Communicator

Perfect. Thanks.

0 Karma
Get Updates on the Splunk Community!

Cloud Platform | Customer Change Announcement: Email Notification Will Be Available ...

The Notification Team is migrating our email service provider from Postmark to AWS Simple Email ...

Mastering Synthetic Browser Testing: Pro Tips to Keep Your Web App Running Smoothly

To start, if you're new to synthetic monitoring, I recommend exploring this synthetic monitoring overview. In ...

Splunk Edge Processor | Popular Use Cases to Get Started with Edge Processor

Splunk Edge Processor offers more efficient, flexible data transformation – helping you reduce noise, control ...