ikke / phpzabbix
PHP Zabbix API Client
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-12 16:23:05 UTC
README
Zabbix PHP API library based on pyzabbix.
Example
$api = phpzabbix\PHPZabbix::withDefaultClient('http://example.com/zabbix/api_jsonrpc.php');
$api->login('username', 'password');
$hosts = $api->host->get(['output' => ['hostid', 'name']]);
It's also possible to directly set the authorization token, either obtained earlier by logging in, or an API token:
$api = phpzabbix\PHPZabbix::withDefaultClient('http://example.com/zabbix/api_jsonrpc.php');
$api->authToken = 'abcdef123456';
$hosts = $api->host->get(['output' => ['hostid', 'name']]);
Error handling
The following exceptions can be thrown:
-
phpzabbix\Exception\NotAuthorizedwhen trying to make an API call with an invalid or expired auth hash. -
phpzabbix\Exception\InvalidCredentialswhen trying to login with invalid credentials. -
phpzabbix\JSONRPC\ErrorExceptionon other errors, such as invalid API calls
Documentation
The PHPZabbix class does not know every API call, but just translates
$api->obj->method() to 'obj.method'. The method call takes an array which
is passed as params.
Refer to the Zabbix API for more information about the Zabbix API itself.
Compattibility
This library should work with Zabbix 3.0 and higher. Older versions should also work, but that has not been verified.
Running tests
The unit and integration tests can be run using docker compose. The Zabbix and
PHP versions can be selected with ZABBIX_VERSION (default 7.4) and
PHP_VERSION (default 8.1):
docker compose run --rm test
ZABBIX_VERSION=6.0 PHP_VERSION=8.3 docker compose run --rm integration-test
The integration tests read the API settings from the ZABBIX_API_URL,
ZABBIX_API_USERNAME, ZABBIX_API_PASSWORD and ZABBIX_API_TOKEN environment
variables, or from integration/settings.php (see settings.dist.php).
License
This code is distributed under the GPLv3 license.