..

How to get data from Zabbix

Posted September 24, 2014

Zabbix is an enterprise monitoring solution for networks and applications.

This solution collects metrics and generates events that can be interesting to retrieve and push to another piece of software. In this article we will review the different ways to get data from this solution.

Different ways to get data from Zabbix

There are 3 ways to get data from Zabbix :

  • By using the Zabbix JSON-RPC API
  • Query the database directly
  • By using alertscripts

The standard way : the JSON-RPC API

Using the JSON-RPC API is the standard way to get data from Zabbix. Almost all third party software for Zabbix I know are using the API with a generic JSON-RPC library or a open source library dedicated to Zabbix’s API.

The JSON-RPC API is included in Zabbix’s frontend.

A list of libraries dedicated to Zabbix’s API (written in Python, Ruby, Perl, PHP, JavaScript, C# or Go) is available here : https://zabbix.org/wiki/Docs/api/libraries.

Zabbix API’s official documentation is available for multiple versions : 1.8, 2.0, 2.2 and 2.4.

The downside of this method is that it is not suited to get data in realtime. This method is great for building new interfaces (web or mobile) and do some reporting but not to send events in real time to another software.

The raw way : query the database directly

Writing portable queries is difficult because Zabbix supports multiple database backends. I do not recommend this method not only because of its difficulty but also because it is possible that the table structures change.

Zabbix’s frontend is a precious ally with this method : sample SQL queries are findable in the frontend’s source code. Additionally, there is a trick to get quickly the right SQL query : you can hack the frontend’s code to log the SQL queries used by the web interface. You just have to build the right view in the web interface to obtain the correct SQL query in order to get the data you want.

It is a good idea to learn the Zabbix API anyway to understand fully how the data is stored and filtered.

The realtime way : using an alert script

This method is successfully employed by many to support external incident management systems.

We can configure Zabbix to execute a script to alert somebody if any event occur. The script is called with 3 parameters : “To”, “Subject” and “Message”. The trick is to configure Zabbix to execute the script anytime and for any event and to populate the “Message” with data in a JSON, YAML or .ini format.

Some examples of integration guide with Zabbix using alert scripts :

The alert script method is well suited when your need is to send Zabbix events in real time.


author Philippe LewinWritten by Philippe Lewin, French Software Engineer. twitter