Build Status Stories in Ready License: GPL v3

Zabbix PHP Loadable Module :

This directory contains from Zabbix v2.2 a Loadable module, which extends functionality of Zabbix Agent/Server/Proxy.

This module add the ability to load PHP interpreter inside Zabbix Server/Proxy/Agent address space.

Is based on my precedente work to add the possibility to call script inside the zabbix engine. At this time I talked with Alexei Vladishev to add the ability to load module … Now it’s done!

With that module you can extend functionality of the Zabbix with PHP module at the infinite.

Prerequisite :

The PHP Embed SAPI - :

Install it on ubuntu trusty :

# apt-get install libphp5-embed php5-dev

Install it on centos 7 :

# yum install php-embedded php-cli php-devel 

Or compile it (the important option are “–enable-embed”) from php 5.6 source :

# wget
# tar xzvf php-5.6.tar.gz
# cd php*5.6*
# ./buildconf
# ./configure --enable-embed --prefix=/path/to/php/install/dir \
		      --with-snmp=shared --with-ldap=shared --enable-shared=yes  \
		      --with-curl=shared  --with-mysqli=shared 
# make
# make install

For example to have embeded library with snmp, ldap, curl and mysqli shared module.

How to Build the module

Compile the zbx_php module with php :

For have get zabbix include necessary to build the module you must download zabbix source :

# wget --content-disposition ""
# tar xzvf zabbix*.tar.gz
# cd zabbix*
# ./configure
# cd -

Them compile the module.

# ./
# ./configure --with-php=/path/to/php/script/php-config 
# make
# make install

It should produce in /path/to/zabbix/install/modules/dir.

Configure zbx_php with zabbix

Zabbix agent, server and proxy support two parameters to deal with modules:

For example, to extend Zabbix agent we could add the following parameters:


Upon agent startup it will load the modules from the /path/to/zabbix/install/modules/dir directory. It will fail if a module is missing, in case of bad permissions or if a shared library is not a Zabbix module.

Zabbix Frontend configuration

Loadable modules are supported by Zabbix agent, server and proxy. Therefore, item type in Zabbix frontend depends on where the module is loaded. If the module is loaded into the agent, then the item type should be “Zabbix agent” or “Zabbix agent (active)”. If the module is loaded into server or proxy, then the item type should be “Simple check”.

Configure module

The module as config file in the same place of the Zabbix Agentd/Server/proxy are, named zbx_php.conf.

for the moment containt only one parameter PHP_SCRIPT_PATH, that specify where php script are searched to execute:


How to test module

To get php version with what the module are compiled :

# zabbix_get  -s -k zbx_php.version

To ping the module:

# zabbix_get  -s -k

How to code script

Generale example are :

   return $myitemvalue;

$myitemvalue can be numeric (integer or float/double), string or boulean.

The module set the type returned correctly accordingly to the dectected type from php variable.

The module set “max_execution_time” according to “Timeout” zabbix configuration setting, after this time the php interpreter interupt the script and zabbix receve “ZBX_NOT_SUPPORTED” on the metric item.

Warning note :

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, etc. is not included when determining the maximum time that the script has been running.

You must pay attention on this when you code your scripts because Zabbix not abort your script on timeout and they can block zabbix unlimitedly if you call PHP extension that block…

The module set tree variable to the script:

By default the php ini parametter are to :

To execute the script “test.php” in “PHP_SCRIPT_PATH” directory with arguments “mon test a moi” by the module:

# zabbix_get  -s -k php[test.php,mon test a moi]


With this items php[snmpget.php,<hostname>,<community>,<oid>] they do snmp get of the oid on <hostname>, with <community>.

snmpget.php :

	$snmp_retval = snmpget($zabbix_hostname, $zabbix_community, $zabbix_oid);
	return $snmp_retval;

to use:

# zabbix_get  -s -k php[snmpget.php,myhost,mycommunity,IF-MIB::ifInOctets.1]

You can find sample script in “scripts_examples” folder of the project.

Some idea that can do with this module