2015-01-01 10:04:34 +01:00
|
|
|
#! /bin/sh
|
|
|
|
# Inspired by https://github.com/cmur2/munin-openweather
|
|
|
|
# Steve Schnepp
|
|
|
|
|
|
|
|
# This part is taken from the original plugin
|
|
|
|
# Example usage:
|
|
|
|
# Do
|
2015-01-01 15:09:08 +01:00
|
|
|
# ln -s /path/to/openweather_ openweather_<query_string>
|
|
|
|
# where <query_string> is either a search query "q_Paris" or
|
|
|
|
# or an id search "id_2988507"
|
2015-01-01 10:04:34 +01:00
|
|
|
#
|
2015-01-01 15:09:08 +01:00
|
|
|
# These parameters translate directly into a URL formed like this:
|
|
|
|
# http://api.openweathermap.org/data/<api>/weather?<query_string>
|
2015-01-01 10:04:34 +01:00
|
|
|
#
|
|
|
|
|
2015-10-13 17:48:04 +02:00
|
|
|
## From Oct 9 2015 OpenWeather needs you to register and get an APIKEY
|
|
|
|
# include this key by setting 'env.apikey' in munin plugin config, i.e.:
|
|
|
|
# [openweather_*]
|
2017-05-30 12:38:45 +02:00
|
|
|
# env.apikey XYZ
|
2015-10-13 17:48:04 +02:00
|
|
|
|
2017-05-30 12:38:45 +02:00
|
|
|
location=$(printf '%s' "${0#*_}" | tr '_' '=')
|
2017-05-31 11:25:16 +02:00
|
|
|
query_string="${location}&appid=${apikey}"
|
2015-10-07 17:09:44 +02:00
|
|
|
plugin_name=$( basename $0 )
|
2015-01-01 10:04:34 +01:00
|
|
|
|
2015-10-05 20:19:14 +02:00
|
|
|
OWAPI=$( curl -s "http://api.openweathermap.org/data/2.5/weather?mode=xml&${query_string}")
|
2017-05-31 11:25:16 +02:00
|
|
|
KELVIN_BIAS=273
|
2015-01-01 10:04:34 +01:00
|
|
|
|
2015-10-05 20:19:14 +02:00
|
|
|
CITY=$( expr "$OWAPI" : '.*\<city.*name=\"\(.*\)\"><coord.*' )
|
2015-01-01 15:09:08 +01:00
|
|
|
|
|
|
|
if [ "$1" = "config" ];
|
|
|
|
then
|
|
|
|
cat <<- EOF
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Temperature in ${CITY}
|
|
|
|
graph_vlabel Celsius
|
2017-02-24 17:30:35 +01:00
|
|
|
graph_category sensors
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the temperature in ${CITY}
|
|
|
|
temp_avg.label avg
|
2017-05-31 11:25:16 +02:00
|
|
|
temp_avg.cdef temp_avg,$KELVIN_BIAS,-
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.temp
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Temperature in ${CITY}
|
|
|
|
graph_vlabel Celsius
|
2017-02-24 17:30:35 +01:00
|
|
|
graph_category sensors
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the temperature in ${CITY}
|
|
|
|
temp_avg.label avg
|
2017-05-31 11:25:16 +02:00
|
|
|
temp_avg.cdef temp_avg,$KELVIN_BIAS,-
|
2015-01-01 15:09:08 +01:00
|
|
|
temp_min.label min
|
2017-05-31 11:25:16 +02:00
|
|
|
temp_min.cdef temp_min,$KELVIN_BIAS,-
|
2015-01-01 15:09:08 +01:00
|
|
|
temp_max.label max
|
2017-05-31 11:25:16 +02:00
|
|
|
temp_max.cdef temp_max,$KELVIN_BIAS,-
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.humidity
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Humidity in ${CITY}
|
|
|
|
graph_vlabel %
|
2017-02-24 17:30:35 +01:00
|
|
|
graph_category sensors
|
2017-05-30 21:16:43 +02:00
|
|
|
graph_args --upper-limit 100 --lower-limit 0
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the humidity in ${CITY}
|
2017-05-31 11:25:16 +02:00
|
|
|
field_humidity.label humidity
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.pressure
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Pressure in ${CITY}
|
|
|
|
graph_vlabel hPa
|
2017-05-30 12:38:45 +02:00
|
|
|
graph_category sensors
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the pressure in ${CITY}
|
2017-05-31 11:25:16 +02:00
|
|
|
field_pressure.label pressure
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.wind_speed
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Wind Speed in ${CITY}
|
|
|
|
graph_vlabel m/s
|
2017-02-24 17:30:35 +01:00
|
|
|
graph_category sensors
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the wind speed in ${CITY}
|
|
|
|
speed.label wind speed
|
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.wind_direction
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_title Wind direction in ${CITY}
|
2017-05-30 12:38:45 +02:00
|
|
|
graph_vlabel direction
|
2017-02-24 17:30:35 +01:00
|
|
|
graph_category sensors
|
2017-05-30 21:16:43 +02:00
|
|
|
graph_args --upper-limit 360 --lower-limit 0
|
2015-01-01 15:09:08 +01:00
|
|
|
graph_info This graph show the wind direction in ${CITY}
|
|
|
|
direction.label wind direction
|
2017-05-30 21:16:43 +02:00
|
|
|
|
2015-01-01 15:09:08 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Continue if dirty config is enabled
|
2018-04-07 02:11:05 +02:00
|
|
|
[ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ] || exit 0
|
2015-01-01 15:09:08 +01:00
|
|
|
fi
|
|
|
|
|
2015-10-05 20:19:14 +02:00
|
|
|
TEMP_AVG=$( expr "$OWAPI" : '.*\<temperature value=\"\(.*\)\" min.*/temperature.*' )
|
|
|
|
TEMP_MIN=$( expr "$OWAPI" : '.*\<temperature .*min=\"\(.*\)\" max.*/temperature.*' )
|
|
|
|
TEMP_MAX=$( expr "$OWAPI" : '.*\<temperature .*max=\"\(.*\)\" unit.*/temperature.*' )
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-05 20:19:14 +02:00
|
|
|
HUMIDITY=$( expr "$OWAPI" : '.*\<humidity .*value=\"\(.*\)\" unit.*/humidity.*' )
|
|
|
|
PRESSURE=$( expr "$OWAPI" : '.*\<pressure .*value=\"\(.*\)\" unit.*/pressure.*' )
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-05 20:19:14 +02:00
|
|
|
WD_SPEED=$( expr "$OWAPI" : '.*\<speed .*value=\"\(.*\)\" name.*/speed.*' )
|
|
|
|
WD_DIREC=$( expr "$OWAPI" : '.*\<direction .*value=\"\(.*\)\" code.*/direction.*' )
|
2015-01-01 15:09:08 +01:00
|
|
|
|
|
|
|
cat <<- EOF
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name
|
2017-05-30 12:38:45 +02:00
|
|
|
temp_avg.value $TEMP_AVG
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.temp
|
2015-01-01 15:09:08 +01:00
|
|
|
temp_avg.value $TEMP_AVG
|
|
|
|
temp_min.value $TEMP_MIN
|
|
|
|
temp_max.value $TEMP_MAX
|
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.humidity
|
2017-05-31 11:25:16 +02:00
|
|
|
field_humidity.value $HUMIDITY
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.pressure
|
2017-05-31 11:25:16 +02:00
|
|
|
field_pressure.value $PRESSURE
|
2015-01-01 15:09:08 +01:00
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.wind_speed
|
2015-01-01 15:09:08 +01:00
|
|
|
speed.value $WD_SPEED
|
|
|
|
|
2015-10-07 17:09:44 +02:00
|
|
|
multigraph $plugin_name.wind_direction
|
2015-11-07 17:41:55 +01:00
|
|
|
direction.value $WD_DIREC
|
2015-01-01 15:09:08 +01:00
|
|
|
EOF
|
|
|
|
|
2015-01-01 10:04:34 +01:00
|
|
|
|
|
|
|
exit 0
|
2015-01-01 15:09:08 +01:00
|
|
|
|
|
|
|
: <<EOF
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<current>
|
|
|
|
<city id="2988507" name="Paris">
|
|
|
|
<coord lon="2.35" lat="48.85"/>
|
|
|
|
<country>FR</country>
|
|
|
|
<sun rise="2015-01-01T07:43:52" set="2015-01-01T16:04:40"/>
|
|
|
|
</city>
|
|
|
|
<temperature value="275.099" min="275.099" max="275.099" unit="kelvin"/>
|
|
|
|
<humidity value="100" unit="%"/>
|
|
|
|
<pressure value="1038.33" unit="hPa"/>
|
|
|
|
<wind>
|
|
|
|
<speed value="2.46" name="Light breeze"/>
|
|
|
|
<direction value="190.509" code="S" name="South"/>
|
|
|
|
</wind>
|
|
|
|
<clouds value="0" name="clear sky"/>
|
|
|
|
<visibility/>
|
|
|
|
<precipitation mode="no"/>
|
|
|
|
<weather number="800" value="Sky is Clear" icon="01d"/>
|
|
|
|
<lastupdate value="2015-01-01T11:42:50"/>
|
|
|
|
</current>
|
|
|
|
EOF
|