# How to write this algorithm in Logstash and display the new fields in Kibana

(Alex) #1

Hello Geeks

I have this pesudo code that I want to translate into a Logstash plugin and show the lat and long fields into Kibana ...

Assume the following variables are to be used in the calculation/conversion:

x_range = 2360
y_range = 718
lat_min = -45.025760784097045
lat_max = 45
long_min = -105
long_max = 104.96748940076955
lat_range = lat_max - lat_min
long_range = long_max - long_min

Based on this you need to project the coordinate onto the lat/long space.

lat = lat_min + (Y * lat_range / y_range)
long = long_min + (X * long_range / x_range)

As I am not a Ruby developer I couldn't translate this into a Ruby filter ;'))
and display the new fields into Kibana

Thanks very much for you efforts ;)))

How to write this equation in LogStash lat = lat_min + (Y * lat_range / y_range) long = long_min + (X * long_range / x_range)
(Andrew Cholakian) #2

The ruby code should be something like:

``````event.set('[lat]', event.get('[lat_min]') + (event.get('[y]') * event.get('[lat_range]') / event.get('[y_range]') )
``````

That assumes the values you provided are included as fields on the event. If that is not the case, then you can just sub out any occurrence of `event.get('[field]')` with a constant like `2360`.

for the lat, you'd need a second line doing the same for long of course. Also, you'd need to set the `y` property in logstash.

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.