From 5dff343760374b77971b1230b5c38dbcd5c16110 Mon Sep 17 00:00:00 2001 From: n Date: Sat, 26 Feb 2022 17:05:12 +0100 Subject: [PATCH] use OpenWeather API as source for collectweather.sh (fixes #1) --- README.md | 2 +- monitoring/collectweather.sh | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1345a5a..5225e5a 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Monitoring * [check_gemini.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_gemini.sh) => Nagios/Icinga check for Gemini capsule availability. Requires gnutls for now (not tested with other tls clients). * [check_lastdate.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/check_lastdate.sh) => Check for a +%Y-%m-%d %H:%M:%S-formated date in the last two lines of a file. * [GonKyrellM](https://forge.tourmentine.com/n/scripts/src/master/monitoring/GonKyrellM) => Conky, GKrellM style - with "invisible" theme (well, sort of) - * [collectweather.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/collectweather.sh) => get weather data from https://darksky.net/ and feed collectd with it. needs jq as Dark Sky provides data in json format. + * [collectweather.sh](https://forge.tourmentine.com/n/scripts/src/master/monitoring/collectweather.sh) => get weather data from https://openweathermap.org/ and feed collectd with it. needs jq as OpenWeather provides data in json format. Attic ----- diff --git a/monitoring/collectweather.sh b/monitoring/collectweather.sh index 3d1de9b..6b21bae 100755 --- a/monitoring/collectweather.sh +++ b/monitoring/collectweather.sh @@ -2,16 +2,15 @@ HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}" INTERVAL="${COLLECTD_INTERVAL:-300}" -FILE="/home/weather/tmp/weather.json" +FILE="/home/weather/tmp/openweathermap.json" -# get $FILE using a cronjob (no more than 1000 requests per day for free - one every 5 minutes is fine) like -#curl "https://api.darksky.net/forecast//,?lang=&units=si" -o $FILE -s +# get $FILE using a cronjob (no more than 1M requests per month/1 request per second for free - one every 5 minutes is fine) like +# curl "https://api.openweathermap.org/data/2.5/weather?lat=&lon=&units=metric&lang=&appid=" -o $FILE -s while sleep "$INTERVAL"; do - for field in precipIntensity precipProbability temperature apparentTemperature dewPoint humidity pressure windSpeed windGust windBearing cloudCover uvIndex visibility ozone;do - echo "PUTVAL $HOSTNAME/weather/gauge-${field} interval=$INTERVAL N:`jq .currently.${field} $FILE`" ; - done - for field in summary icon ;do - echo "PUTVAL $HOSTNAME/weather/string-${field} interval=$INTERVAL N:`jq .currently.${field} $FILE`" ; + for field in main.temp main.feels_like main.pressure main.humidity wind.speed wind.gust clouds.all rain.\"1h\" rain.\"3h\" snow.\"1h\" snow.\"3h\" sys.sunrise sys.sunset visibility;do + key=`echo ${field} | sed 's/\./-/g' | sed 's/"//g'` + echo "PUTVAL $HOSTNAME/weather/gauge-${key} interval=$INTERVAL N:`jq .${field} $FILE | sed s/null/0/g`" ; done done +