Splunk Search

How to join and get stats from same index?

vikas_gopal
Builder

Hi Experts,

I have data set like below from same index but from different sourcetype, common field on which I can join is aapid, app_id. I want to only show those app id which take more than 20 min time for approval .

Sourcetye=created
    date,status,appid
    18/Oct/2018 05:05:02,created,1234
    18/Oct/2018 05:06:02,created,12345
    18/Oct/2018 05:07:02,created,123456

Sourcetye=approved
date,status,app_id
18/Oct/2018 05:25:02,approved,1234
18/Oct/2018 05:40:02,approved,12345

On the above sample data set I am expacting a table like below.

Appid,Created time , Approved time ,totoal_time
12345,18/Oct/2018 05:06:02,18/Oct/2018 05:40:02,34min

Regards
VG

1 Solution

anmolpatel
Builder

@vikas_gopal something as such ?

| makeresults
| eval _raw = "
sourcetype, date,status,appid
created, 18/Oct/2018 05:05:02,created,1234, 
created, 18/Oct/2018 05:06:02,created,12345, 
created, 18/Oct/2018 05:07:02,created,123456"     
| multikv forceheader=1 
| stats values(date) as created_date by appid
| join type=outer appid [ |makeresults
         | eval _raw = "sourcetype,date,status,app_id
approved, 18/Oct/2018 05:25:02,approved,1234
approved, 18/Oct/2018 05:40:02,approved,12345
approved, 18/Oct/2018 05:17:02,created,123456"
         | multikv forceheader=1 
         | stats values(date) as approved_date by app_id
         | rename app_id as appid]
         | where approved_date!= ""
         | eval total_time = strftime((strptime(approved_date, "%d/%b/%Y %H:%M:%S") - strptime(created_date, "%d/%b/%Y %H:%M:%S")), "%M")
         | where total_time >= 20
         | eval "Total Time" = total_time." mins"
         | rename appid as Appid approved_date as "Approved Date" created_date as "Created Date"
         | fields Appid "Created Date" "Approved Date" "Total Time"

alt text

View solution in original post

anmolpatel
Builder

@vikas_gopal something as such ?

| makeresults
| eval _raw = "
sourcetype, date,status,appid
created, 18/Oct/2018 05:05:02,created,1234, 
created, 18/Oct/2018 05:06:02,created,12345, 
created, 18/Oct/2018 05:07:02,created,123456"     
| multikv forceheader=1 
| stats values(date) as created_date by appid
| join type=outer appid [ |makeresults
         | eval _raw = "sourcetype,date,status,app_id
approved, 18/Oct/2018 05:25:02,approved,1234
approved, 18/Oct/2018 05:40:02,approved,12345
approved, 18/Oct/2018 05:17:02,created,123456"
         | multikv forceheader=1 
         | stats values(date) as approved_date by app_id
         | rename app_id as appid]
         | where approved_date!= ""
         | eval total_time = strftime((strptime(approved_date, "%d/%b/%Y %H:%M:%S") - strptime(created_date, "%d/%b/%Y %H:%M:%S")), "%M")
         | where total_time >= 20
         | eval "Total Time" = total_time." mins"
         | rename appid as Appid approved_date as "Approved Date" created_date as "Created Date"
         | fields Appid "Created Date" "Approved Date" "Total Time"

alt text

vikas_gopal
Builder

Worked like Charm the mistake I was doing was is values(date) . That did a trick . Thanks

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...