Splunk Search

Geographical distance calculation in Splunk Cloud (replacing haversine)

rcornett
New Member

Hi all,

 

We are currently migrating from Splunk on-premise to the Cloud. One of the apps we heavily use is haversine to calculate the distance between 2 locations.

 

I haven't been able to find a cloud-ready replacement for this. Just looking for recommendations on an app or solution to be able to do this in the cloud?

 

Cheers,

Ryan

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

I created a haversine macro (from macros.conf)

[haversine(4)]
args = source_lat, source_lon, dest_lat, dest_lon
definition = eval hv_rlat1 = pi()*$dest_lat$/180, hv_rlat2=pi()*$source_lat$/180, hv_rlat = pi()*($source_lat$-$dest_lat$)/180, hv_rlon= pi()*($source_lon$-$dest_lon$)/180 \
| eval hv_a = sin(hv_rlat/2) * sin(hv_rlat/2) + cos(hv_rlat1) * cos(hv_rlat2) * sin(hv_rlon/2) * sin(hv_rlon/2) \
| eval hv_c = 2 * atan2(sqrt(hv_a), sqrt(1-hv_a)) \
| eval distance = round(6371 * hv_c * 1000,0)\
| fields - hv_rlat, hv_rlat1, hv_rlat2, hv_rlon, hv_rlon1, hv_a, hv_c
iseval = 0

 Here's the distance from Sydney to San Francisco

| makeresults
| eval source_lat=-33.8688, source_lon=151.2093, dest_lat=37.7749, dest_lon=-122.4194
| `haversine(source_lat, source_lon, dest_lat, dest_lon)`
| eval distance_in_km=distance/1000
| table distance_in_km

Hope this helps

 

0 Karma

rcornett
New Member

@bowesmana awesome, thank you! I will give it ago and see if it works with our current application. Thank you 🙂

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@rcornett 

If it works for you, please remember to mark is as the solution, so others can make use of it

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...