From c8f30b09569fa0361df1be49288f0af932558c79 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 1 Jan 2015 09:04:34 +0000 Subject: [PATCH 1/2] 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 From 2c5943e46965560f704969a174d740d1cfd0723f Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Thu, 1 Jan 2015 14:09:08 +0000 Subject: [PATCH 2/2] p: updating openweather_ to be multigraph Now it graph all the values coming from the API --- plugins/weather/openweather_ | 153 +++++++++++++++++++++++++++-------- 1 file changed, 120 insertions(+), 33 deletions(-) diff --git a/plugins/weather/openweather_ b/plugins/weather/openweather_ index d8a5a51e..47b1c128 100644 --- a/plugins/weather/openweather_ +++ b/plugins/weather/openweather_ @@ -5,48 +5,135 @@ # 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= +# ln -s /path/to/openweather_ openweather_ +# where is either a search query "q_Paris" or +# or an id search "id_2988507" # -# Example config: -# [openweather_*] +# These parameters translate directly into a URL formed like this: +# http://api.openweathermap.org/data//weather? # -entity_id=${0##*_} +query_string=$(printf '%s' "${0#*_}" | tr '_' '=') TMPFILE=$(mktemp) trap 'rm -f $TMPFILE' EXIT +# API returns temp in K, we have to convert it in C KELVIN_BIAS=273 -curl -s "http://openweathermap.org/data/2.5/weather?id=${entity_id}" | tr ':{},' ' \n' > $TMPFILE +curl -s "http://api.openweathermap.org/data/2.5/weather?mode=xml&${query_string}" > $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 ))" - } +CITY=$(fgrep " + + + + FR + + + + + + + + + + + + + + + +EOF