Configure OpenWeather - jonatello/farmalytics GitHub Wiki

Open Weather Map is a great free solution for pulling publicly available weather information. These steps will show how to use their API to pull results into Logstash. I'll be configuring this directly on the host running Logstash, in this case version 6.4.2 and running on FreeBSD.

Create Open Weather Map account

To use Open Weather Map's API you must first register for an account, after that you'll be able to generate an API key which will be used in the HTTP requests as the APPID. Information can be pulled in a lot of different ways, but using the City ID is a simple way. Search for and find your location on the site, then in the URL you will see the City ID after the '/city/'.

Configure with Python

Install Python and the Requests module

pkg install python py37-requests

Place the outside.py script in the root folder (/root)

Replace the APPID and CITYID placeholders with the actual values, they're currently setup to be used as environmental variables 'OW_CITY_ID' and 'OW_API_KEY'

Test running the script and verify Temp and Humidity values are returned

python ./outside.py

Save these to a log to be consumed with Logstash or use one of the many other methods available such as Filebeat for this to be eventually ingested into Elasticsearch

Configure with Logstash via Http_poller

A simpler approach might be to use the Http_poller module in Logstash. Essentially logstash.conf just needs the following added within the existing Input block (replace 'CITY_ID' and 'API_KEY' appropriately)

# input for OWM http_poller { urls => { owm => "https://api.openweathermap.org/data/2.5/weather?id=CITY_ID&APPID=API_KEY&units=imperial" } request_timeout => 20 schedule => { every =>"60s" } }