From c8f30b09569fa0361df1be49288f0af932558c79 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 1 Jan 2015 09:04:34 +0000 Subject: [PATCH] p: adding openweather_ --- plugins/weather/openweather_ | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 plugins/weather/openweather_ diff --git a/plugins/weather/openweather_ b/plugins/weather/openweather_ new file mode 100644 index 00000000..d8a5a51e --- /dev/null +++ b/plugins/weather/openweather_ @@ -0,0 +1,52 @@ +#! /bin/sh +# Inspired by https://github.com/cmur2/munin-openweather +# Steve Schnepp + +# This part is taken from the original plugin +# Example usage: +# Do +# ln -s /path/to/openweather_ openweather__ +# where is currently ignored (formerly one of +# [station, weather]) and is a suitable +# city id from http://openweathermap.org/ +# These parameters translate directly into a URL formed like this: +# http://openweathermap.org/data//weather?id= +# +# Example config: +# [openweather_*] +# + +entity_id=${0##*_} +TMPFILE=$(mktemp) +trap 'rm -f $TMPFILE' EXIT + +KELVIN_BIAS=273 + +curl -s "http://openweathermap.org/data/2.5/weather?id=${entity_id}" | tr ':{},' ' \n' > $TMPFILE + +while read KEY VALUE EXTRA +do + [ "$KEY" = '"main"' ] && KEY=$VALUE && VALUE=$EXTRA + [ "$KEY" = '"temp"' ] && { + VALUE=${VALUE%%.*} + [ "$1" != "config" ] && echo "temp.value $(( $VALUE - $KELVIN_BIAS ))" + } + + [ "$KEY" = '"name"' ] && { + [ "$1" = "config" ] && { + cat <<- EOF + graph_title Temperature in ${VALUE} + graph_args --lower-limit 0 + graph_vlabel Celsius + graph_category weather + graph_scale no + graph_info This graph show the temperature in ${VALUE} + temp.label temperature + temp.info Temperature in degree Celsius + temp.type GAUGE + EOF + } + } +done < $TMPFILE + +exit 0