Download the PHP package kamermans/zabbix-client without Composer
On this page you can find all versions of the php package kamermans/zabbix-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zabbix-client
zabbix-client
This is a simple, yet powerful Zabbix API client for PHP. I have made no attempt to model the Zabbix API in PHP functions, but rather, I have made the interface extremely easy to use in order to query the Zabbix JSON-RPC API.
There are several examples in examples/
that should be quite useful. You can even make a copy of zabbix_auth.php
and call it zabbix_auth_local.php
and that file will be used by the examples instead, so you don't need to taint the git repo.
Compatibility
This library is designed and tested for Zabbix 2.2 and it's likely to have problems with other versions. If you want to add support for 2.4 (or any other version) you are more than welcome :)
Authentication
Zabbix uses a username and password to connect initially, then an auth token for subsequent requests.
Here's how you connect and authenticate:
Calling Zabbix Endpoints
All the Zabbix endpoints are described in the Zabbix Documentation.
To call and endpoint, use the $client->request(string endpoint, array params=[])
method:
Note that $response
is a kamermans\ZabbixClient\ApiResponse
object that has some magical properties. In the example above, the Zabbix endpoint apiinfo.version
returns a single string, so you can use $response
as a string as well.
Most endpoints return an associative array as a response:
As you can see, you can iterate over the response object (although it's still a kamermans\ZabbixClient\ApiResponse
).
In this example we also passed an array of parameters as the second argument.
Error Handling
When the Zabbix API returns an error, it is wrapped up into a proper exception and thrown.
There are three types of exceptions that you can catch inside the kamermans\ZabbixClient
namespace:
Exception
: base class used for generic exceptions. All exceptions extend this one.ApiException
: all API calls that returned a parseable JSON response are wrapped by this exception which gives you a well-formed error message from Zabbix and access to raw response viaApiException::getResponse()
.AuthException
: an extention ofApiException
that only gets thrown for authentication errors so they can be handled differently.
Utility Functions
Response Dumping
For easy troubleshooting of responses, you can use the ApiResponse::dump()
function to output the response to the screen, or ApiResponse::dd()
to dump and die:
Server Ping
There is a utility function to check to latency (in milliseconds) to the Zabbix Server API:
Complete Example
This example lists all the system items in the Zabbix Server:
Output: