use OpenWeather API as source for collectweather.sh (fixes #1)

This commit is contained in:
n 2022-02-26 17:05:12 +01:00
parent 6bebeb943e
commit 5dff343760
Signed by: n
GPG key ID: 510227DD6C502CE3
2 changed files with 8 additions and 9 deletions

View file

@ -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_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. * [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) * [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 Attic
----- -----

View file

@ -2,16 +2,15 @@
HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}" HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-300}" 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 # 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.darksky.net/forecast/<your api key>/<latitude>,<longitude>?lang=<language>&units=si" -o $FILE -s # curl "https://api.openweathermap.org/data/2.5/weather?lat=<latitude>&lon=<longitude>&units=metric&lang=<language>&appid=<your api key>" -o $FILE -s
while sleep "$INTERVAL"; do while sleep "$INTERVAL"; do
for field in precipIntensity precipProbability temperature apparentTemperature dewPoint humidity pressure windSpeed windGust windBearing cloudCover uvIndex visibility ozone;do 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
echo "PUTVAL $HOSTNAME/weather/gauge-${field} interval=$INTERVAL N:`jq .currently.${field} $FILE`" ; key=`echo ${field} | sed 's/\./-/g' | sed 's/"//g'`
done echo "PUTVAL $HOSTNAME/weather/gauge-${key} interval=$INTERVAL N:`jq .${field} $FILE | sed s/null/0/g`" ;
for field in summary icon ;do
echo "PUTVAL $HOSTNAME/weather/string-${field} interval=$INTERVAL N:`jq .currently.${field} $FILE`" ;
done done
done done