mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
p: updating openweather_: replaced fgrep, tr, cut with expr
Use expr to extract values and names from the OpenWeather API xml instead of the - when using a city with spaces in its name not correctly working - fgrep | tr | cut construct.
This commit is contained in:
parent
07428a0137
commit
7d1ac56eae
1 changed files with 10 additions and 12 deletions
22
plugins/weather/openweather_
Normal file → Executable file
22
plugins/weather/openweather_
Normal file → Executable file
|
@ -19,15 +19,13 @@
|
||||||
# env.apikey XYZ
|
# env.apikey XYZ
|
||||||
|
|
||||||
query_string=$(printf '%s' "${0#*_}" | tr '_' '=')
|
query_string=$(printf '%s' "${0#*_}" | tr '_' '=')
|
||||||
TMPFILE=$(mktemp)
|
|
||||||
trap 'rm -f $TMPFILE' EXIT
|
|
||||||
|
|
||||||
|
OWAPI=$( curl -s "http://api.openweathermap.org/data/2.5/weather?mode=xml&${query_string}")
|
||||||
# API returns temp in K, we have to convert it in C
|
# API returns temp in K, we have to convert it in C
|
||||||
|
# &units=metric would change that ;-)
|
||||||
KELVIN_BIAS=273
|
KELVIN_BIAS=273
|
||||||
|
|
||||||
curl -s "http://api.openweathermap.org/data/2.5/weather?mode=xml&${query_string}&APPID=${apikey}" > $TMPFILE
|
CITY=$( expr "$OWAPI" : '.*\<city.*name=\"\(.*\)\"><coord.*' )
|
||||||
|
|
||||||
CITY=$(fgrep "<city id=" $TMPFILE | tr -sc '[:alnum:]' ' ' | cut -d " " -f 6)
|
|
||||||
|
|
||||||
if [ "$1" = "config" ];
|
if [ "$1" = "config" ];
|
||||||
then
|
then
|
||||||
|
@ -85,15 +83,15 @@ then
|
||||||
[ "$MUNIN_CAP_DIRTYCONFIG" = 1 ] || exit 0
|
[ "$MUNIN_CAP_DIRTYCONFIG" = 1 ] || exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEMP_AVG=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
|
TEMP_AVG=$( expr "$OWAPI" : '.*\<temperature value=\"\(.*\)\" min.*/temperature.*' )
|
||||||
TEMP_MIN=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 6)
|
TEMP_MIN=$( expr "$OWAPI" : '.*\<temperature .*min=\"\(.*\)\" max.*/temperature.*' )
|
||||||
TEMP_MAX=$(fgrep "<temperature value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 8)
|
TEMP_MAX=$( expr "$OWAPI" : '.*\<temperature .*max=\"\(.*\)\" unit.*/temperature.*' )
|
||||||
|
|
||||||
HUMIDITY=$(fgrep "<humidity value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
|
HUMIDITY=$( expr "$OWAPI" : '.*\<humidity .*value=\"\(.*\)\" unit.*/humidity.*' )
|
||||||
PRESSURE=$(fgrep "<pressure value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
|
PRESSURE=$( expr "$OWAPI" : '.*\<pressure .*value=\"\(.*\)\" unit.*/pressure.*' )
|
||||||
|
|
||||||
WD_SPEED=$(fgrep "<speed value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
|
WD_SPEED=$( expr "$OWAPI" : '.*\<speed .*value=\"\(.*\)\" name.*/speed.*' )
|
||||||
WD_DIREC=$(fgrep "<direction value=" $TMPFILE | tr -sc '[:alnum:].' ' ' | cut -d " " -f 4)
|
WD_DIREC=$( expr "$OWAPI" : '.*\<direction .*value=\"\(.*\)\" code.*/direction.*' )
|
||||||
|
|
||||||
cat <<- EOF
|
cat <<- EOF
|
||||||
multigraph $0
|
multigraph $0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue