Download the PHP package cinexpert/php-zabbix-api without Composer
On this page you can find all versions of the php package cinexpert/php-zabbix-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-zabbix-api
PhpZabbixApi
I'M LOOKING FOR CONTRIBUTORS, CLICK HERE FOR MORE INFORMATIONS
About
PhpZabbixApi is an open-source PHP class library to communicate with the Zabbix™ JSON-RPC API.
Because PhpZabbixApi is generated directly from the origin Zabbix™ 2.0 PHP front-end source code / files, each real Zabbix™ JSON-RPC API method is implemented (hard-coded) directly as an own PHP method. This means PhpZabbixApi is IDE-friendly, because you've a PHP method for each API method, and there are no PHP magic functions or alike.
License
PhpZabbixApi is licensed under the MIT license.
Getting the thing
You can get PhpZabbixApi in 3 different ways:
Make sure the version of the library matches the Zabbix™ PHP front-end / API version.
Building
If you want to build your own library, have a look at the configuration file inc/config.inc.php
.
You might want to point PATH_ZABBIX
to your Zabbix™ installation directory.
If you setup everything correctly, you should be able to create the library by executing:
There are also pre-built libraries available in the build/
directory, if you don't want to build it yourself.
Download
Download a release and extract the pre-built PHP library from the build/
directory.
Make sure you've downloaded the following files and stored them in the same directory:
ZabbixApi.class.php
ZabbixApiAbstract.class.php
For example:
Composer
If you're using PHP composer, you can load the library directly via:
All tagged versions can be installed, for example:
If you're looking for more "bleeding-edge" versions (e.g. for testing), then you could also use branches:
Using the thing
Naming concept
To translate a Zabbix™ API call into a PHP method call, you can simply
- remove the dot
- capitalize the first letter of the action
Example:
Customizing the API class
By default there are only 2 classes defined:
If you want to customize or extend the library, you might want to do that in the ZabbixApi
class.
Out of the box, ZabbixApi
is an empty class inherited from ZabbixApiAbstract
.
By customizing only ZabbixApi
, you're able to update ZabbixApiAbstract
(the build) at any time, without merging your customizations manually.
Basic usage
To use the PhpZabbixApi you just have to load ZabbixApi.class.php
, create a new ZabbixApi
instance, and you're ready to go:
The API can also work with HTTP Basic Authroization, you just have to call the constructor with additional parameters:
Examples
Simple request
Here's a simple request to fetch all defined graphs via graph.get API method:
Request with parameters
Most of the time you want to define some specific parameters. Here's an example to fetch all CPU graphs via graph.get API method:
Define default parameters
Sometimes you want to define default parameters, which will be included in each API request.
You can do that by defining the parameters in an array via setDefaultParams()
:
Get associative / un-indexed array
By default all API responses will be returned in an indexed array.
So if you then looking for a specific named graph, you've to loop through the indexed array and compare the name
attribute of each element. This can be a bit of a pain, and because of that, there's a simple way to to get an associative instead of an indexed array. You just have to define the 2nd parameter of the API method, which is the name of attribute you'd like to use as an array key.
Here's an example to fetch all graphs in an associative array, with the graph's name
as array key: