Monitoring weather with Zabbix

Zabbix has proven itself successful as an IT monitoring solution when there is a need to oversee the health of hundreds and thousands of servers. However, there is no reason to think that such a powerful system can only do just that – monitor computers. In the first such post today, we will try to uncover the potential of how Zabbix can be used in a multitude of different ways.

As the post title suggests, today we will setup Zabbix to monitor weather. There are many weather API’s out there, but two of them – Yahoo! Weather RSS Feed and Google Weather API – are equally convenient to get started with and require no registration to use. For the purposes of this post, we will use Yahoo! Weather, since it provides a bit more information.

To obtain a weather forecast from Yahoo!, we use an URL of the form http://weather.yahooapis.com/forecastrss?w=location&u=units, where location is a WOEID (see request summary for how to find yours) and units is either c for Celsius and metric units or f for Fahrenheit and English units.

For instance, the weather forecast for Riga, Latvia can be obtained by visiting the URL http://weather.yahooapis.com/forecastrss?w=854823&u=c and looks as follows (stripped of irrelevant information and reformatted for brevity and clarify, respectively):

<rss>
  <channel>
    <yweather:location city="Riga" country="Latvia"/>
    <yweather:units temperature="C" distance="km"
                    pressure="mb" speed="km/h" />
    <yweather:wind chill="16" direction="20" speed="20.92" />
    <yweather:atmosphere humidity="55" visibility="9.99"
                         pressure="982.05" />
    <yweather:astronomy sunrise="6:25 am" sunset="8:21 pm" />
    <item>
      <yweather:condition text="Fair" code="34" temp="16"
                          date="Wed, 01 Sep 2010 12:50 am EEST" />
      <yweather:forecast day="Wed" date="1 Sep 2010" code="30"
                         low="11" high="17" text="Partly Cloudy" />
      <yweather:forecast day="Thu" date="2 Sep 2010" code="12"
                         low="10" high="12" text="Rain/Wind" />
    </item>
  </channel>
</rss>

Now that we know what information is out there, we need to create a template with corresponding items and triggers. The example template we have developed can be downloaded from here (right click to save as file) and can be seen on the following screenshots:

Items of Template_Weather

Triggers of Template_Weather

The triggers are designed to let you know whether there is going to be a cold or hot weather, according to the forecast. By creating actions for the weather triggers, you can receive email or SMS alerts, so that you always know what to wear and whether you need to take an umbrella with you!

The parsing of the weather XML is done with a Perl script that is run every hour by cron. The script uses zabbix_sender to send metrics to the server. You can download the script from here and adjust the first four variables to match your environment. As an example, the weather conditions for today in Riga, Latvia can be seen in “Latest data” below:

Conditions in Riga, Latvia

Unfortunately, what Zabbix does not currently allow you to do in an elegant way, is to receive weather forecasts, regardless of whether the forecast is problematic or not. The only way seems to be creating an action for a dummy trigger that will always be on. There is an issue, ZBXNEXT-415, about it on Zabbix bug tracker, and you can vote for it, if you need this possibility in the daily IT administration work.

This is it for this blog post. May you all have a good weather today!

3 thoughts on “Monitoring weather with Zabbix”

  1. Why not add the Perl script as “External check” to the template? No need to add it to cron, just let Zabbix schedule the script. Btw, thank you for the script and template, I installed it and it works great. I added some graphs, for example to visualize the actual temperature and the wind chill temperature or the wind direction and speed.

    1. Adding the script as an “External check” is a nice option, too.

      Recently, several bugs have been fixed in the template. One of those bugs is that the attached template did not have trigger dependencies, as depicted on the screenshot.

      Another bug was that the item type for weather.condition[temperature] was wrongly set to “Numeric (unsigned)”, while it should have been “Numeric (float)”. It gets colder in Riga, and the bug became a problem when the temperature dropped below zero and the item became unsupported.

      One of the nice features of Zabbix in this regard is that graphs will still show both the old, “Numeric (unsigned)”, and the new, “Numeric (float)”, values. Thus, there is no need to worry that historical data will be lost when changing an item type.

      Also note that the number of unsupported items in Zabbix database can be monitored using the internal item zabbix[items_unsupported]. This will not show which items exactly became unsupported, but still it might be a good hint whenever something goes wrong.

Leave a Reply