Collect weather conditions from openweathermap.org using host coordinates and Zabbix built-in HTTP agent + some JS preprocessing (Zabbix 4.2), HTTP agent only ( Zabbix 4.0 ) or perl script(Zabbix < 4.0).
http://openweathermap.org/appid
- Import sample template for Zabbix 2.4-3.4 or for Zabbix 4.2, 4.0.
Currently supported items:
Item | key | via script(Zabbix 2.4+) | via HTTP agent(Zabbix 4.0) | via HTTP agent+JS* (Zabbix 4.2+) |
---|---|---|---|---|
Temperature | temp | Y | Y | Y |
Humidity | humidity | Y | Y | Y |
Visibility | visibility | Y | Y | Y |
Is dark | is_dark | Y | N | Y* |
Wind speed | wind.speed | Y | Y | Y |
Weather status | weather | Y | Y | Y |
Weather description | weather.description | Y | Y | Y |
Weather condition id | weather.condition.id | Y | Y | Y |
- Add global/template level Macro
{$WEATHER_APIKEY} = YOURKEY
add another global macro as prefered language for weather descriptions:
{$WEATHER_LANG} = en
Add macros {$LAT} and {$LON} for each host that requires weather monitoring:
For Zabbix 2.4-3.4, please read below how to setup the collector script.
0. Dependencies
The script is written in Perl and you will need common modules in order to run it:
LWP
JSON::XS
There are numerous ways to install them:
in Debian | In Centos | using CPAN | using cpanm |
---|---|---|---|
apt-get install libwww-perl libjson-xs-perl |
yum install perl-JSON-XS perl-libwww-perl perl-LWP-Protocol-https |
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install Bundle::LWP' and PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install JSON::XS' |
cpanm install LWP and cpanm install JSON::XS |
- place get_weather.pl into externalscripts folder
then:
chmod +x get_weather.pl
chown zabbix:zabbix get_weather.pl
- Check that it is working
./get_weather.pl -lat 55.672944 -lon 38.478944 --hostname TEST --api_key YOURKEY
You should receiveOK
as script output.
2.1. If you need to use http proxy:
Make sure that you have environment variables http_proxy
and https_proxy
defined under user zabbix
For example:
export http_proxy=http://proxy_ip:3129/
export https_proxy=$http_proxy
./get_weather.pl -lat 55.672944 -lon 38.478944 --hostname TEST --api_key YOURKEY
Note: It would more logical to use Latitue and Longitude Inventory fields and not user macros, but {INVENTORY.*} values cannot be used in items keys.
A feature request to change that is here: https://support.zabbix.com/browse/ZBXNEXT-2546.