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

Event Series: The Agentic SOC: Trust Before Autonomy

AI is fundamentally changing security operations, but true progress requires more than just automation—it ...

Free Professional Services for .conf26 Attendees

This year at .conf26, we are doing something a little different. We are bringing the best minds from ...

Defend at Machine Speed: Your Guide to Security Sessions at .conf26

Splunk .conf26   With threats moving at machine speed and attack surfaces expanding across hybrid ...