1. Go to this page and download the library: Download cinexpert/php-zabbix-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cinexpert / php-zabbix-api example snippets
// load ZabbixApi
;
try
{
// connect to Zabbix API
$api = new ZabbixApi('http://zabbix.confirm.ch/api_jsonrpc.php', 'zabbix_user', 'zabbix_password');
/* ... do your stuff here ... */
}
catch(Exception $e)
{
// Exception in ZabbixApi catched
echo $e->getMessage();
}
// connect to Zabbix API with HTTP basic auth
$api = new ZabbixApi('http://zabbix.confirm.ch/api_jsonrpc.php', 'zabbix_user', 'zabbix_password', 'http_user', 'http_password');
// get all graphs
$graphs = $api->graphGet();
// print all graph IDs
foreach($graphs as $graph)
echo $graph->graphid."\n";
// get all graphs named "CPU"
$cpuGraphs = $api->graphGet(array(
'output' => 'extend',
'search' => array('name' => 'CPU')
));
// print graph ID with graph name
foreach($cpuGraphs as $graph)
printf("id:%d name:%s\n", $graph->graphid, $graph->name);
// use extended output for all further requests
$api->setDefaultParams(array(
'output' => 'extend'
));
// get all graphs named "CPU"
$cpuGraphs = $api->graphGet(array(
'search' => array('name' => 'CPU')
));
// print graph ID with graph name
foreach($cpuGraphs as $graph)
printf("id:%d name:%s\n", $graph->graphid, $graph->name);
// get all graphs in an associative array (key=name)
$graphs = $api->graphGet(array(), 'name');
// print graph ID with graph name
if(array_key_exists('CPU Load Zabbix Server', $graphs))
echo 'CPU Load graph exists';
else
echo 'Could not find CPU Load graph';