2019-05-27 22:36:08 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2023-10-19 17:53:44 +02:00
|
|
|
HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
|
2019-05-27 22:36:08 +02:00
|
|
|
INTERVAL="${COLLECTD_INTERVAL:-300}"
|
2022-02-26 17:05:12 +01:00
|
|
|
FILE="/home/weather/tmp/openweathermap.json"
|
2019-05-27 22:36:08 +02:00
|
|
|
|
2022-02-26 17:05:12 +01:00
|
|
|
# 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=<latitude>&lon=<longitude>&units=metric&lang=<language>&appid=<your api key>" -o $FILE -s
|
2019-05-27 22:36:08 +02:00
|
|
|
|
|
|
|
while sleep "$INTERVAL"; do
|
2022-02-26 17:05:12 +01:00
|
|
|
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
|
2023-10-19 17:53:44 +02:00
|
|
|
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)" ;
|
2019-05-27 22:36:08 +02:00
|
|
|
done
|
|
|
|
done
|
2022-02-26 17:05:12 +01:00
|
|
|
|